allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [16/20] git commit: [#7257] ticket:587 Get rid of unnecessary add_projects tasks
Date Wed, 21 May 2014 14:45:04 GMT
[#7257] ticket:587 Get rid of unnecessary add_projects tasks


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

Branch: refs/heads/master
Commit: 2d7c518e02e880b444b1d594139b24f5ae2d12fc
Parents: 76120b2
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue May 13 17:52:27 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed May 21 14:44:22 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/search.py    |  8 ++++++++
 Allura/allura/model/project.py | 12 +++++++++++-
 Allura/allura/model/session.py |  9 +++++++--
 3 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/2d7c518e/Allura/allura/lib/search.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index 89daac4..b0d7e4b 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -77,6 +77,14 @@ class SearchIndexable(object):
         """
         raise NotImplementedError
 
+    def should_update_index(self, old_doc, new_doc):
+        """Determines if solr index should be updated.
+
+        Values passed as old_doc and new_doc are original and modified
+        versions of same object, represented as dictionaries.
+        """
+        return True
+
     def solarize(self):
         doc = self.index()
         if doc is None:

http://git-wip-us.apache.org/repos/asf/allura/blob/2d7c518e/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 53184ff..7f43849 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -1040,7 +1040,6 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                       is_root_b=self.is_root,
                       is_nbhd_project_b=self.is_nbhd_project,
                       registration_dt=plugin.ProjectRegistrationProvider.get().registration_date(self),
-                      last_updated_dt=self.last_updated,
                       removal_changed_date_dt=self.removal_changed_date,
                       name_s=self.name,
                       shortname_s=self.shortname,
@@ -1056,6 +1055,17 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                           category_description_t=self.category.description)
         return dict(provider.index_project(self), **fields)
 
+    def should_update_index(self, old_doc, new_doc):
+        """Skip index update if only `last_updated` has changed.
+
+        Value of `last_updated` is updated whenever any artifact
+        that belongs to project is changed. This generates a lot of
+        unnecessary `add_projects` tasks for every simple user action.
+        """
+        old_doc.pop('last_updated', None)
+        new_doc.pop('last_updated', None)
+        return old_doc != new_doc
+
     def __json__(self):
         result = dict(
             shortname=self.shortname,

http://git-wip-us.apache.org/repos/asf/allura/blob/2d7c518e/Allura/allura/model/session.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/session.py b/Allura/allura/model/session.py
index 7a2c2a4..f364aeb 100644
--- a/Allura/allura/model/session.py
+++ b/Allura/allura/model/session.py
@@ -76,12 +76,17 @@ class IndexerSessionExtension(ManagedSessionExtension):
         task = tasks.get(action)
         if task:
             if action == 'add':
-                arg = [o._id for o in obj_list]
+                def _needs_update(o):
+                    old = dict(state(o).original_document)
+                    new = dict(state(o).document)
+                    return o.should_update_index(old, new)
+                arg = [o._id for o in obj_list if _needs_update(o)]
             else:
                 arg = [o.index_id() for o in obj_list]
 
             try:
-                task.post(arg)
+                if arg:
+                    task.post(arg)
             except:
                 log.error('Error calling %s', task.__name__)
 


Mime
View raw message