Anonymous avatar Anonymous committed 2d2111c

Added history tracking for the database signalling system. This should
help us to improve the search indexer.

Comments (0)

Files changed (3)

solace/database.py

         pk = (orm.object_mapper(model).primary_key_from_instance(model))
         pk.append(type(model))
         pk = tuple(pk)
-        orm.object_session(model)._model_changes[pk] = (model, operation)
+        orm.object_session(model)._model_changes[pk] = (model, operation, None)
         return EXT_CONTINUE
 
 
 class SignalEmittingSessionExtension(SessionExtension):
     """Emits signals the mapper extension accumulated."""
 
+    def after_flush(self, session, flush_context):
+        d = session._model_changes
+        if d:
+            # this is the last time we can access the history.  Add the
+            # information about changed columns to the change records.
+            for key, (model, operation, _) in d.iteritems():
+                if operation != 'update':
+                    continue
+                state = orm.attributes.instance_state(model)
+                changed_columns = []
+                for attr in state.manager.attributes:
+                    if attr.get_history(model, passive=True).has_changes():
+                        changed_columns.append(attr.key)
+                d[key] = (model, operation, frozenset(changed_columns))
+        return EXT_CONTINUE
+
     def before_commit(self, session):
         d = session._model_changes
         if d:

solace/signals.py

 SIG('before_response_sent', ['request', 'response'])
 
 #: emitted after some models where properly comitted to the database.  The
-#: changes list a list of ``(model, operation)`` tuples.  Operation is a
-#: string that can either be "insert", "update" or "delete".
+#: changes list a list of ``(model, operation, columns)`` tuples.  Operation
+#: is a string that can either be "insert", "update" or "delete" and
+#: columns a set of altered columns.
 SIG('after_models_committed', ['changes'])
 
 #: like `after_models_committed` but fired before the actual commit.  Mostly

solace/views/kb.py

     """Allows searching for topics"""
     form = SearchForm()
     results = None
-    if 'q' in request.args and form.validate():
+    if request.args and form.validate():
         results = form.get_results()
     return render_template('kb/search.html', results=results,
                            form=form.as_widget())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.