You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2021/02/16 13:40:05 UTC

[allura] branch kt/icon-hash updated (0969d4d -> 57ae2c4)

This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a change to branch kt/icon-hash
in repository https://gitbox.apache.org/repos/asf/allura.git.


 discard 0969d4d  fixup! SF-5746 use project icon file hash for cache busting
 discard 6bc9780  SF-5746 use project icon file hash for cache busting
     new 57ae2c4  SF-5746 use project icon file hash for cache busting

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (0969d4d)
            \
             N -- N -- N   refs/heads/kt/icon-hash (57ae2c4)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:


[allura] 01/01: SF-5746 use project icon file hash for cache busting

Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch kt/icon-hash
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 57ae2c4ee697a3c60d3c1eb4b9b67cc01c4b7be0
Author: Kenton Taylor <kt...@slashdotmedia.com>
AuthorDate: Wed Feb 10 18:34:58 2021 +0000

    SF-5746 use project icon file hash for cache busting
---
 Allura/allura/ext/admin/admin_main.py |  2 +-
 Allura/allura/model/project.py        | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index a2384bd..26380b2 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -335,7 +335,7 @@ class ProjectAdminController(BaseController):
             c.project.removal_changed_date = datetime.utcnow()
         if 'delete_icon' in kw:
             M.ProjectFile.query.remove(dict(project_id=c.project._id, category=re.compile(r'^icon')))
-            c.project.set_tool_data('allura', icon_original_size=None)
+            c.project.set_tool_data('allura', icon_original_size=None, icon_sha256=None)
             M.AuditLog.log('remove project icon')
             g.post_event('project_updated')
             redirect('overview')
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 68585b7..5819a8f 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -21,6 +21,8 @@ from __future__ import absolute_import
 import logging
 from calendar import timegm
 from collections import Counter, OrderedDict
+from hashlib import sha256
+
 from datetime import datetime
 from copy import deepcopy
 import six.moves.urllib.request
@@ -380,8 +382,18 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
         )
         # store the dimensions so we don't have to read the whole image each time we need to know
         icon_orig_img = PIL.Image.open(icon_orig.rfile())
+
         self.set_tool_data('allura', icon_original_size=icon_orig_img.size)
 
+        try:
+            # calc and save icon file hash, for better cache busting purposes
+            file_input.seek(0)
+            file_bytes = file_input.read()
+            file_sha256 = sha256(file_bytes).hexdigest()
+            self.set_tool_data('allura', icon_sha256=file_sha256)
+        except Exception as ex:
+            log.exception('Failed to calculate sha256 for icon file for {}'.format(self.shortname))
+
     @property
     def icon(self):
         return self.icon_sized(DEFAULT_ICON_WIDTH)