You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by he...@apache.org on 2015/04/14 19:34:15 UTC

[1/2] allura git commit: [#7852] Fixed an issue where 'mod_time' was getting updated on the first view.

Repository: allura
Updated Branches:
  refs/heads/hs/7852 [created] fd3c07456


[#7852] Fixed an issue where 'mod_time' was getting updated on the first view.


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/acaa3b05
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/acaa3b05
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/acaa3b05

Branch: refs/heads/hs/7852
Commit: acaa3b0563fd135ce5b92c5771af93a90dc99e30
Parents: 33dcb08
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Tue Apr 14 13:29:20 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Tue Apr 14 13:29:20 2015 -0400

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/acaa3b05/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 30bfbf3..31f3c79 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -63,6 +63,7 @@ from allura.lib.widgets import analytics
 from allura.lib.security import Credentials
 from allura.lib.solr import MockSOLR, make_solr_from_config
 from allura.lib.zarkov_helpers import ZarkovClient
+from allura.model.session import artifact_orm_session
 
 log = logging.getLogger(__name__)
 
@@ -104,11 +105,13 @@ class ForgeMarkdown(markdown.Markdown):
             return self.convert(source_text)
 
         md5 = None
+        # If a cached version exists and it is valid, return it.
         if cache.md5 is not None:
             md5 = hashlib.md5(source_text.encode('utf-8')).hexdigest()
             if cache.md5 == md5 and getattr(cache, 'fix7528', False):
                 return h.html.literal(cache.html)
 
+        # Convert the markdown and time the result.
         start = time.time()
         html = self.convert(source_text)
         render_time = time.time() - start
@@ -121,11 +124,16 @@ class ForgeMarkdown(markdown.Markdown):
             log.warn('Skipping Markdown caching - The value for config param '
                      '"markdown_cache_threshold" must be a float.')
 
-        if threshold != None and render_time > threshold:
+        if threshold is not None and render_time > threshold:
+            # Save the cache
             if md5 is None:
                 md5 = hashlib.md5(source_text.encode('utf-8')).hexdigest()
             cache.md5, cache.html, cache.render_time = md5, html, render_time
             cache.fix7528 = True  # flag to indicate good caches created after [#7528] was fixed
+
+            # Prevent cache creation from updating the mod_date timestamp.
+            _session = artifact_orm_session._get()
+            setattr(_session, 'skip_mod_date', True)
         return html
 
 


[2/2] allura git commit: [#7852] Added tests to confirm 'mod_time' field does not get updated on page view.

Posted by he...@apache.org.
[#7852] Added tests to confirm 'mod_time' field does not get updated on page view.


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/fd3c0745
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/fd3c0745
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/fd3c0745

Branch: refs/heads/hs/7852
Commit: fd3c074568d7b2aeb5585dc604ce2e5ca208bd2f
Parents: acaa3b0
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Tue Apr 14 13:31:12 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Tue Apr 14 13:31:12 2015 -0400

----------------------------------------------------------------------
 .../forgetracker/templates/tracker/ticket.html  |  2 +-
 .../forgetracker/tests/functional/test_root.py  | 21 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/fd3c0745/ForgeTracker/forgetracker/templates/tracker/ticket.html
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/templates/tracker/ticket.html b/ForgeTracker/forgetracker/templates/tracker/ticket.html
index 27331c8..5f9f534 100644
--- a/ForgeTracker/forgetracker/templates/tracker/ticket.html
+++ b/ForgeTracker/forgetracker/templates/tracker/ticket.html
@@ -123,7 +123,7 @@
     <div style="clear:both"></div>
     <div class="grid-4">
       <label class="simple">Updated:</label>
-      {{abbr_date(ticket.mod_date)}}
+      <span id="updated_id">{{abbr_date(ticket.mod_date)}}</span>
     </div>
     <div class="grid-4">
       <label class="simple">Created:</label>

http://git-wip-us.apache.org/repos/asf/allura/blob/fd3c0745/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 0e92b1f..1ecfa2c 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -16,6 +16,7 @@
 #       KIND, either express or implied.  See the License for the
 #       specific language governing permissions and limitations
 #       under the License.
+from datetime import datetime
 
 import urllib
 import os
@@ -720,6 +721,26 @@ class TestFunctionalController(TrackerTestController):
         r = self.app.get('/bugs/markdown_syntax')
         assert_true('Markdown Syntax' in r)
 
+    @patch.dict('allura.lib.app_globals.config', markdown_cache_threshold='0')
+    @patch('allura.lib.app_globals.ForgeMarkdown.cached_convert')
+    def test_cached_convert(self, mock_cached_convert):
+        from allura.model.session import artifact_orm_session
+        # Create ticket
+        params = dict(ticket_num=1,
+                      app_config_id=c.app.config._id,
+                      summary=u'test md cache',
+                      mod_date=datetime(2010, 1, 1, 1, 1, 1))
+        ticket = tm.Ticket(**params)
+        session = artifact_orm_session._get()
+        setattr(session, 'skip_mod_date', True)
+
+        # This visit will cause cache to be stored on the artifact.
+        # We want to make sure the 'last_updated' field isn't updated by the cache creation
+        r = self.app.get('/bugs/1').follow()
+        last_updated = r.html.find("span", {"id": "updated_id"}).text
+        assert_equal(last_updated, '2010-01-01')
+        assert_equal(mock_cached_convert.call_count, 1)
+
     def test_ticket_diffs(self):
         self.new_ticket(summary='difftest', description='1\n2\n3\n')
         self.app.post('/bugs/1/update_ticket', {