~ubuntuone-hackers/django-modeldict/trunk

Viewing all changes in revision 65.

  • Committer: Jeff Pollard
  • Date: 2012-11-09 22:20:41 UTC
  • Revision ID: git-v1:e7e896bcee4619eb7ae1a16b6ad245f8a5d5039e
Fix bug that caused us to pull down things every time

Summary:
So there was a bug in modeldict that caused the entire switch set to be pulled from cache any time `_cleanup()` was called on the modeldict, which happened every time the `request_finished` and `task_postrun` signals were fired.  This was bad, as it means we have a cache `get()` calls to pull down the heavy switch set every single page load and celery task.

The bug happened because `_cleanup()` reset the `_last_checked_for_remote_changes` variable to `None`, effectively clobbering any information that the modeldict had to know what it's own personal `last_modified` timestamp was.  Thus, it had no way to know if the remote cache had changed given its version.

Practically, it caused this line of code to be run:

```
return int(cache_last_updated) > self._last_checked_for_remote_changes
```

`cache_last_updated` was the timestamp of the `last_updated` value in remote cache (when the switch set last changed), and `self._last_checked_for_remote_changes` was `None`, reset by `_cleanup()`.  No matter what valid `cache_last_updated` value there is, comparing `any_value > None` is always `True`, so the modeldict thought that remote had changes and it pulled them down.

The change was to add a separate `_local_last_updated` instance variable that actually tracked the cached `last_updated` value.  This leaves `_last_checked_for_remote_changes` to only be used to track when the modeldict last synced its local cache with the remote one, and to be reset without blowing away the locally cached `last_updated` value.

Test Plan: Existing tests, plus I added another test that asserts when cleanup is called it does not `get()` the whole switch set from the cache.

Reviewers: dcramer, ted

Reviewed By: dcramer

Differential Revision: http://phabricator.local.disqus.net/D4150

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: