mitsuhiko  committed 2d2111c

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

  • Participants
  • Parent commits 59fec2f
  • Branches default

Comments (0)

Files changed (3)

File solace/

         pk = (orm.object_mapper(model).primary_key_from_instance(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:

File solace/

 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

File solace/views/

     """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,