Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old scales upon image update #3

Merged
merged 2 commits into from
Nov 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plone/scale/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def scale(self, factory=None, **parameters):
info = storage.get(key)
modified = self.modified and self.modified()
if info is not None and modified > info['modified']:
del storage[info['uid']]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried upgrading a site to Plone 4.3.3, and this is breaking for me in a case where the info['uid'] key is not found for some reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird while without an uid you can not get to the image scale (if you create unique URLs for images). Anyway, should I add a check that uid is present?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may have something to do with the fact that this is a local copy of a large site, for debugging, and I didn't copy the blobs but instead hacked the ZODB blob code to return empty files instead of erroring.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that broke also a site of mine in production. @mauritsvanrees pull-request #4 fixes that.

info = None # invalidate when the image was updated
if info is None and factory:
result = factory(**parameters)
Expand Down
12 changes: 12 additions & 0 deletions plone/scale/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ def testDeleteRemovesItemAndIndex(self):
del storage[scale['uid']]
self.assertEqual(len(storage), 0)

def testCleanUpOldItems(self):
storage = self.storage
scale_old = storage.scale(factory=self.factory, foo=23, bar=42)
next_modified = storage.modified() + 1
storage.modified = lambda: next_modified
scale_new = storage.scale(factory=self.factory, foo=23, bar=42)
self.assertEqual(len(storage), 2)
self.assertEqual(scale_new['uid'] in storage, True)
self.assertEqual(scale_old['uid'] in storage, False)
del storage[scale_new['uid']]
self.assertEqual(len(storage), 0)


def test_suite():
from unittest import defaultTestLoader
Expand Down