Skip to content

Commit

Permalink
Fix bug where cached value wasn't used when value was 0
Browse files Browse the repository at this point in the history
When debugging the `is_last_child` cache, I saw the value
of cache.get() here is either 1, 0, or None if the cached
value isn't present. Currently, only values of 1 are getting
used, because if the value is 0, the `if v:` to check if
the cache is present fails. I think we need to be more
specific here and do: `if v is not None:`

This change improved performance a little bit in my local testing
with memcached, but it's still not great: Calling the cache for
each node in the tree takes time, and it would be great to find
a way to interact with the cache just once for the pagetree edit
page.

refs #63
  • Loading branch information
nikolas committed May 2, 2015
1 parent 79969a7 commit 4b3569c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.1.3
==================
* Fixed a bug that prevented cached values from getting used,
if the value was 0.

1.1.2 (2015-04-22)
==================
* Add confirmation page when deleting a pageblock.
Expand Down
6 changes: 3 additions & 3 deletions pagetree/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def is_first_child(self):
def is_last_child(self):
key = "pagetree.%d.is_last_child" % self.id
v = cache.get(key)
if v:
if v is not None:
statsd.incr("pagetree.is_last_child.cache_hit")
return v
statsd.incr("pagetree.is_last_child.cache_miss")
Expand Down Expand Up @@ -287,7 +287,7 @@ def __unicode__(self):
def get_absolute_url(self):
key = "pagetree.%d.get_absolute_url" % self.id
v = cache.get(key)
if v:
if v is not None:
statsd.incr("pagetree.get_absolute_url.cache_hit")
return v
statsd.incr("pagetree.get_absolute_url.cache_miss")
Expand All @@ -307,7 +307,7 @@ def _get_absolute_url(self):
def get_edit_url(self):
key = "pagetree.%d.get_edit_url" % self.id
v = cache.get(key)
if v:
if v is not None:
statsd.incr("pagetree.get_edit_url.cache_hit")
return v
statsd.incr("pagetree.get_edit_url.cache_miss")
Expand Down

0 comments on commit 4b3569c

Please sign in to comment.