Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bug 958285] Bust images cache when answers are edited.

  • Loading branch information...
commit 1d05cd94a446485d54e5431db46af533aee2e45b 1 parent 248dae0
@rlr rlr authored
View
6 kitsune/questions/models.py
@@ -703,6 +703,9 @@ def content_parsed(self):
def clear_cached_html(self):
cache.delete(self.html_cache_key % self.id)
+ def clear_cached_images(self):
+ cache.delete(self.images_cache_key % self.id)
+
def save(self, update=True, no_notify=False, *args, **kwargs):
"""
Override save method to update question info and take care of
@@ -735,6 +738,9 @@ def save(self, update=True, no_notify=False, *args, **kwargs):
# Avoid circular import: events.py imports Question.
from kitsune.questions.events import QuestionReplyEvent
QuestionReplyEvent(self).fire(exclude=self.creator)
+ else:
+ # Clear the attached images cache.
+ self.clear_cached_images()
def delete(self, *args, **kwargs):
"""Override delete method to update parent question info."""
View
26 kitsune/sumo/models.py
@@ -9,19 +9,16 @@
ManagerBase = caching.base.CachingManager
-class ModelBase(caching.base.CachingMixin, models.Model):
- """
- Base class for SUMO models to abstract some common features.
+class NoCacheModelBase(models.Model):
+ """Base class for SUMO models that don't want automatic caching.
- * Caching.
+ * Adds update method.
"""
- objects = ManagerBase()
- uncached = models.Manager()
-
class Meta:
abstract = True
+ # TODO: Remove this in django 1.6, which comes with a smarter save().
def update(self, **kw):
"""
Shortcut for doing an UPDATE on this object.
@@ -47,6 +44,21 @@ def update(self, **kw):
created=False)
+class ModelBase(caching.base.CachingMixin, NoCacheModelBase):
+ """
+ Base class for SUMO models to abstract some common features.
+
+ * Caching.
+ * Adds update method.
+ """
+
+ objects = ManagerBase()
+ uncached = models.Manager()
+
+ class Meta:
+ abstract = True
+
+
# This adds rules that South needs for introspection so it can do
# migrations correctly.
from south.modelsinspector import add_introspection_rules
View
4 kitsune/upload/models.py
@@ -5,12 +5,12 @@
from django.db import models
from kitsune.sumo.helpers import reverse
-from kitsune.sumo.models import ModelBase
+from kitsune.sumo.models import NoCacheModelBase
from kitsune.sumo.utils import auto_delete_files
@auto_delete_files
-class ImageAttachment(ModelBase):
+class ImageAttachment(NoCacheModelBase):
"""An image attached to an object using a generic foreign key"""
file = models.ImageField(upload_to=settings.IMAGE_UPLOAD_PATH,
max_length=settings.MAX_FILEPATH_LENGTH)
View
8 kitsune/upload/tests/test_views.py
@@ -95,7 +95,7 @@ def test_delete_image_logged_out(self):
self.client.logout()
r = self._make_post_request(args=[im.id])
eq_(403, r.status_code)
- assert ImageAttachment.uncached.exists()
+ assert ImageAttachment.objects.exists()
def test_delete_image_no_permission(self):
"""Can't delete an image without permission."""
@@ -106,7 +106,7 @@ def test_delete_image_no_permission(self):
self.client.login(username='tagger', password='testpass')
r = self._make_post_request(args=[im.id])
eq_(403, r.status_code)
- assert ImageAttachment.uncached.exists()
+ assert ImageAttachment.objects.exists()
def test_delete_image_owner(self):
"""Users can delete their own images."""
@@ -116,7 +116,7 @@ def test_delete_image_owner(self):
eq_(200, r.status_code)
json_r = json.loads(r.content)
eq_('success', json_r['status'])
- assert not ImageAttachment.uncached.exists()
+ assert not ImageAttachment.objects.exists()
def test_delete_image_with_permission(self):
"""Users with permission can delete images."""
@@ -133,7 +133,7 @@ def test_delete_image_with_permission(self):
eq_(200, r.status_code)
json_r = json.loads(r.content)
eq_('success', json_r['status'])
- assert not ImageAttachment.uncached.exists()
+ assert not ImageAttachment.objects.exists()
def test_delete_no_image(self):
"""Trying to delete a non-existent image 404s."""
Please sign in to comment.
Something went wrong with that request. Please try again.