Closed Bug 815026 Opened 12 years ago Closed 11 years ago

Bugzilla::Object cache should be cleared when an object is updated or removed from the database

Categories

(Bugzilla :: Bugzilla-General, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
Bugzilla 5.0

People

(Reporter: glob, Assigned: glob)

References

Details

Attachments

(1 file, 1 obsolete file)

Bugzilla::Object cache should be cleared when an object is updated or removed from the database.
Attached patch patch v1 (obsolete) — Splinter Review
while i didn't experience any issues during testing without this patch, it's good practice, and should guard against weird cache issues.
Attachment #685042 - Flags: review?(dkl)
Severity: normal → enhancement
Target Milestone: --- → Bugzilla 5.0
Comment on attachment 685042 [details] [diff] [review]
patch v1

Review of attachment 685042 [details] [diff] [review]:
-----------------------------------------------------------------

::: Bugzilla/Object.pm
@@ +135,5 @@
>  }
>  
> +sub _cache_remove {
> +    my $class = shift;
> +    my ($param, $object) = @_;

Nit: $object not used, at least not in this sub.

@@ +432,4 @@
>      $self->audit_log(\%changes) if $self->AUDIT_UPDATES;
>  
>      $dbh->bz_commit_transaction();
> +    $self->_cache_remove({ id => $self->id });

This will not remove the object if the original object was stored with 'name' in the cache key. For example:

my $user = Bugzilla::User->new({ name => 'dkl@mozilla.com', cache => 1 });
$user->set_name('Dave Lawrence who Rocks');
$user->update();

The object is not deleted from request_cache since _cache_remove calls cache_key which looks the object up by ID instead of NAME.

This is not really an issue with storing the objects as it is OK to have two objects cached, one by ID and another by NAME. Just means the DB would get hit twice which still still gives *some* benefit if the object is requested many times for a single page load. Unless the two differ in some way object wise (another bug?)

@@ +451,4 @@
>      $self->audit_log(AUDIT_REMOVE) if $self->AUDIT_REMOVES;
>      $dbh->do("DELETE FROM $table WHERE $id_field = ?", undef, $self->id);
>      $dbh->bz_commit_transaction();
> +    $self->_cache_remove({ id => $self->id });

ditto
Attachment #685042 - Flags: review?(dkl) → review-
Attached patch 815026_2.patchSplinter Review
Attachment #685042 - Attachment is obsolete: true
Attachment #8345692 - Flags: review?(dkl)
Comment on attachment 8345692 [details] [diff] [review]
815026_2.patch

Review of attachment 8345692 [details] [diff] [review]:
-----------------------------------------------------------------

r=dkl
Attachment #8345692 - Flags: review?(dkl) → review+
Flags: approval?
Flags: approval? → approval+
Committing to: bzr+ssh://bjones%40mozilla.com@bzr.mozilla.org/bugzilla/trunk/
modified Bugzilla/Object.pm
Committed revision 8830.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: