]> git.koha-community.org Git - koha.git/commit
Bug 32894: Remove wrong caching from Koha:: methods - simple
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 28 Feb 2023 15:11:38 +0000 (16:11 +0100)
committerMatt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Wed, 12 Jul 2023 09:10:16 +0000 (09:10 +0000)
commita06def460f0a47074ca22fdf30e4d9c9f9b0ad77
tree7462bd9439753e23e32078b398862643ec5a42d4
parent86fb8f10799384d14c5cae9bd12d11d7fe49bfc6
Bug 32894: Remove wrong caching from Koha:: methods - simple

In some of our Koha:: objects we have methods that cache their result and return it in subsequent calls. However there is no invalidation of the cache if the object is modified.

For instance, in Koha/ArticleRequest.pm

sub biblio {
    my ($self) = @_;

    $self->{_biblio} ||= Koha::Biblios->find( $self->biblionumber() );

    return $self->{_biblio};
}

This pattern exists in several places.

It can lead to confusion and incorrect results, such as:

use Koha::ArticleRequests;
my $ar = Koha::ArticleRequest->new({
    borrowernumber => 42,
    biblionumber => 42,
})->store;
say $ar->biblio->biblionumber;               # Display 42, correct
$ar->set({ biblionumber => 24 })->store;
say $ar->biblio->biblionumber;               # Display 42, wrong
$ar->discard_changes;
say $ar->biblio->biblionumber;               # Display 42, wrong
$ar->delete;

We should remove those caching and rely on DBIC/DBMS caching mechanism instead.

This patch is adjusting the trivial occurrences

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 68216c541bfd9b5baf5e3fe97c0a99d193dfccce)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 3347e6682477acd503c591d24670cd66cccaf38f)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Koha/Account/Line.pm
Koha/ArticleRequest.pm
Koha/Biblio.pm
Koha/CirculationRule.pm
Koha/Hold.pm
Koha/Library/Group.pm
Koha/Object/Limit/Library.pm
Koha/Virtualshelf.pm
Koha/Virtualshelfshare.pm