Skip to content

Commit

Permalink
[fc] Repository: plone.scale
Browse files Browse the repository at this point in the history
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@05d238a

Avoid TypeErrors when looking for outdated scales.

Fixes plone/plone.scale#12

Files changed:
M CHANGES.rst
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@9d95279

When getting an outdated scale, don't throw it away when there is no factory.

Files changed:
M CHANGES.rst
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@bcca32a

modified time can be a long.

Fixes plone.namedfile and plone.app.imaging tests.

Files changed:
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.scale@9d0cf3e

Fix modified scale comparison with offset.

We were subtracting from the wrong value.

Files changed:
M plone/scale/storage.py
Repository: plone.scale
Branch: refs/heads/1.4.x
Date: 2016-10-22T23:07:48-04:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: plone/plone.scale@4938b05

Merge pull request #19 from plone/modified-time-compare-14

Various scale storage bug fixes [1.4.x]

Files changed:
M CHANGES.rst
M plone/scale/storage.py
  • Loading branch information
jensens committed Oct 23, 2016
1 parent db46b10 commit c2b1879
Showing 1 changed file with 326 additions and 23 deletions.
349 changes: 326 additions & 23 deletions last_commit.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,334 @@
Repository: plone.app.upgrade
Repository: plone.scale


Branch: refs/heads/1.3.x
Date: 2016-10-22T14:29:57-04:00
Author: Gil Forcada Codinachs (gforcada) <gil.gnome@gmail.com>
Commit: https://github.com/plone/plone.app.upgrade/commit/94efd6094764172047ed18a2cbb09add0e543159
Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: https://github.com/plone/plone.scale/commit/05d238acdf1049f4bf971d56e256848f6222fa56

Add a note about version compatibility
Avoid TypeErrors when looking for outdated scales.

Fixes https://github.com/plone/plone.scale/issues/12

Files changed:
M CHANGES.rst
M plone/scale/storage.py

diff --git a/CHANGES.rst b/CHANGES.rst
index 4443ece..1145c6c 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -11,6 +11,10 @@ New:

Fixes:

+- Avoid TypeErrors when looking for outdated scales.
+ Fixes `issue 12 <https://github.com/plone/plone.scale/issues/12>`_.
+ [maurits]
+
- Catch KeyError when deleting non existing scale. This can happen in corner cases.
Fixes `issue 15 <https://github.com/plone/plone.scale/issues/15>`_.
[maurits]
diff --git a/plone/scale/storage.py b/plone/scale/storage.py
index 1e50266..e7327de 100644
--- a/plone/scale/storage.py
+++ b/plone/scale/storage.py
@@ -107,13 +107,21 @@ def __init__(self, context, modified=None):
self.context = context
self.modified = modified

- def _modified_since(self, since):
+ def _modified_since(self, since, offset=0):
if since is None:
return False
- elif self.modified_time is None:
+ modified_time = self.modified_time
+ if modified_time is None:
return False
- else:
- return self.modified_time > since
+ # We expect either a float or an int, but in corner cases it can be
+ # something else entirely.
+ # https://github.com/plone/plone.scale/issues/12
+ if not isinstance(modified_time, (float, int)):
+ return False
+ if not isinstance(since, (float, int)):
+ return False
+ since = since - offset
+ return modified_time > since

@property
def modified_time(self):
@@ -176,14 +184,19 @@ def scale(self, factory=None, **parameters):
def _cleanup(self):
storage = self.storage
modified_time = self.modified_time
+ if modified_time is None:
+ return
+ if not isinstance(modified_time, (float, int)):
+ # https://github.com/plone/plone.scale/issues/12
+ return
for key, value in storage.items():
# remove info stored by tuple keys
# before refactoring
if isinstance(key, tuple):
del self[key]
# clear cache from scales older than one day
- elif (modified_time and
- value['modified'] < modified_time - KEEP_SCALE_MILLIS):
+ elif self._modified_since(
+ value['modified'], offset=KEEP_SCALE_MILLIS):
del self[key]

def __getitem__(self, uid):


Repository: plone.scale


Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: https://github.com/plone/plone.scale/commit/9d952798ad52c8bdfd08bb7808694747fd01cefb

When getting an outdated scale, don't throw it away when there is no factory.

Files changed:
M CHANGES.rst
M plone/scale/storage.py

diff --git a/CHANGES.rst b/CHANGES.rst
index 1145c6c..53b33d0 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -11,6 +11,9 @@ New:

Fixes:

+- When getting an outdated scale, don't throw it away when there is no
+ factory. [maurits]
+
- Avoid TypeErrors when looking for outdated scales.
Fixes `issue 12 <https://github.com/plone/plone.scale/issues/12>`_.
[maurits]
diff --git a/plone/scale/storage.py b/plone/scale/storage.py
index e7327de..9c45e79 100644
--- a/plone/scale/storage.py
+++ b/plone/scale/storage.py
@@ -162,7 +162,8 @@ def scale(self, factory=None, **parameters):
key = self.hash(**parameters)
storage = self.storage
info = self.get_info_by_hash(key)
- if info is not None and self._modified_since(info['modified']):
+ if (info is not None and factory and
+ self._modified_since(info['modified'])):
del self[info['uid']]
# invalidate when the image was updated
info = None


Repository: plone.scale


Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: https://github.com/plone/plone.scale/commit/bcca32a1cef525ad288e4e27619f01281cc63eca

modified time can be a long.

Fixes plone.namedfile and plone.app.imaging tests.

Files changed:
M plone/scale/storage.py

diff --git a/plone/scale/storage.py b/plone/scale/storage.py
index 9c45e79..f57c763 100644
--- a/plone/scale/storage.py
+++ b/plone/scale/storage.py
@@ -13,6 +13,8 @@
# This is one day:
KEEP_SCALE_MILLIS = 24 * 60 * 60 * 1000

+number_types = (float, int, long)
+

class IImageScaleStorage(Interface):
""" This is an adapter for image content which can store, retrieve and
@@ -113,12 +115,12 @@ def _modified_since(self, since, offset=0):
modified_time = self.modified_time
if modified_time is None:
return False
- # We expect either a float or an int, but in corner cases it can be
+ # We expect a number, but in corner cases it can be
# something else entirely.
# https://github.com/plone/plone.scale/issues/12
- if not isinstance(modified_time, (float, int)):
+ if not isinstance(modified_time, number_types):
return False
- if not isinstance(since, (float, int)):
+ if not isinstance(since, number_types):
return False
since = since - offset
return modified_time > since
@@ -187,7 +189,7 @@ def _cleanup(self):
modified_time = self.modified_time
if modified_time is None:
return
- if not isinstance(modified_time, (float, int)):
+ if not isinstance(modified_time, number_types):
# https://github.com/plone/plone.scale/issues/12
return
for key, value in storage.items():


Repository: plone.scale


Branch: refs/heads/1.4.x
Date: 2016-10-22T22:53:44-04:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: https://github.com/plone/plone.scale/commit/9d0cf3ec443e1eea78e12ea2af9f7c9978084e1e

Fix modified scale comparison with offset.

We were subtracting from the wrong value.

Files changed:
M plone/scale/storage.py

diff --git a/plone/scale/storage.py b/plone/scale/storage.py
index f57c763..9330b00 100644
--- a/plone/scale/storage.py
+++ b/plone/scale/storage.py
@@ -110,6 +110,9 @@ def __init__(self, context, modified=None):
self.modified = modified

def _modified_since(self, since, offset=0):
+ # offset gets subtracted from the main modified time: this allows to
+ # keep scales for a bit longer if needed, even when the main image has
+ # changed.
if since is None:
return False
modified_time = self.modified_time
@@ -122,7 +125,7 @@ def _modified_since(self, since, offset=0):
return False
if not isinstance(since, number_types):
return False
- since = since - offset
+ modified_time = modified_time - offset
return modified_time > since

@property


Repository: plone.scale


Branch: refs/heads/1.4.x
Date: 2016-10-22T23:07:48-04:00
Author: Jens W. Klein (jensens) <jk@kleinundpartner.at>
Commit: https://github.com/plone/plone.scale/commit/4938b05693bd062171159457bd2731d287f523ff

Merge pull request #19 from plone/modified-time-compare-14

Various scale storage bug fixes [1.4.x]

Files changed:
M README.rst

diff --git a/README.rst b/README.rst
index 00310e2..2f449f1 100644
--- a/README.rst
+++ b/README.rst
@@ -1,5 +1,9 @@
Overview
========
+This package contains the upgrade machinery to upgrade a Plone site to a newer version.

-This package contains the upgrade machinery to upgrade a Plone site to a
-newer version.
+Version compatibility
+---------------------
+To update to Plone 4.x please use plone.app.upgrade versions up to 1.3.x.
M CHANGES.rst
M plone/scale/storage.py

diff --git a/CHANGES.rst b/CHANGES.rst
index 4443ece..53b33d0 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -11,6 +11,13 @@ New:

Fixes:

+- When getting an outdated scale, don't throw it away when there is no
+ factory. [maurits]
+
+To update to Plone 5.x and up, use plone.app.upgrade versions 2.x and up.
+- Avoid TypeErrors when looking for outdated scales.
+ Fixes `issue 12 <https://github.com/plone/plone.scale/issues/12>`_.
+ [maurits]
+
- Catch KeyError when deleting non existing scale. This can happen in corner cases.
Fixes `issue 15 <https://github.com/plone/plone.scale/issues/15>`_.
[maurits]
diff --git a/plone/scale/storage.py b/plone/scale/storage.py
index 1e50266..9330b00 100644
--- a/plone/scale/storage.py
+++ b/plone/scale/storage.py
@@ -13,6 +13,8 @@
# This is one day:
KEEP_SCALE_MILLIS = 24 * 60 * 60 * 1000

+number_types = (float, int, long)
+

class IImageScaleStorage(Interface):
""" This is an adapter for image content which can store, retrieve and
@@ -107,13 +109,24 @@ def __init__(self, context, modified=None):
self.context = context
self.modified = modified

- def _modified_since(self, since):
+ def _modified_since(self, since, offset=0):
+ # offset gets subtracted from the main modified time: this allows to
+ # keep scales for a bit longer if needed, even when the main image has
+ # changed.
if since is None:
return False
- elif self.modified_time is None:
+ modified_time = self.modified_time
+ if modified_time is None:
return False
- else:
- return self.modified_time > since
+ # We expect a number, but in corner cases it can be
+ # something else entirely.
+ # https://github.com/plone/plone.scale/issues/12
+ if not isinstance(modified_time, number_types):
+ return False
+ if not isinstance(since, number_types):
+ return False
+ modified_time = modified_time - offset
+ return modified_time > since

@property
def modified_time(self):
@@ -154,7 +167,8 @@ def scale(self, factory=None, **parameters):
key = self.hash(**parameters)
storage = self.storage
info = self.get_info_by_hash(key)
- if info is not None and self._modified_since(info['modified']):
+ if (info is not None and factory and
+ self._modified_since(info['modified'])):
del self[info['uid']]
# invalidate when the image was updated
info = None
@@ -176,14 +190,19 @@ def scale(self, factory=None, **parameters):
def _cleanup(self):
storage = self.storage
modified_time = self.modified_time
+ if modified_time is None:
+ return
+ if not isinstance(modified_time, number_types):
+ # https://github.com/plone/plone.scale/issues/12
+ return
for key, value in storage.items():
# remove info stored by tuple keys
# before refactoring
if isinstance(key, tuple):
del self[key]
# clear cache from scales older than one day
- elif (modified_time and
- value['modified'] < modified_time - KEEP_SCALE_MILLIS):
+ elif self._modified_since(
+ value['modified'], offset=KEEP_SCALE_MILLIS):
del self[key]

def __getitem__(self, uid):


0 comments on commit c2b1879

Please sign in to comment.