[cleanup] add index_entity to abstract source, add docstring stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 04 Mar 2010 18:04:26 +0100
branchstable
changeset 4807 5642bfa43236
parent 4806 4f12f59b1a13
child 4808 23df4a120c96
child 4809 1e983e926cca
[cleanup] add index_entity to abstract source, add docstring
hooks/syncschema.py
server/sources/__init__.py
server/sources/native.py
--- a/hooks/syncschema.py	Thu Mar 04 18:02:33 2010 +0100
+++ b/hooks/syncschema.py	Thu Mar 04 18:04:26 2010 +0100
@@ -463,17 +463,18 @@
     rschema = values = None # make pylint happy
 
     def precommit_event(self):
+        session = self.session
         etype = self.kobj[0]
         table = SQL_PREFIX + etype
         column = SQL_PREFIX + self.rschema.type
         if 'indexed' in self.values:
-            sysource = self.session.pool.source('system')
+            sysource = session.pool.source('system')
             if self.values['indexed']:
-                sysource.create_index(self.session, table, column)
+                sysource.create_index(session, table, column)
             else:
-                sysource.drop_index(self.session, table, column)
+                sysource.drop_index(session, table, column)
         if 'cardinality' in self.values and self.rschema.final:
-            adbh = self.session.pool.source('system').dbhelper
+            adbh = session.pool.source('system').dbhelper
             if not adbh.alter_column_support:
                 # not supported (and NOT NULL not set by yams in that case, so
                 # no worry)
@@ -485,11 +486,17 @@
             # XXX check self.values['cardinality'][0] actually changed?
             sql = adbh.sql_set_null_allowed(table, column, coltype,
                                             self.values['cardinality'][0] != '1')
-            self.session.system_sql(sql)
+            session.system_sql(sql)
         if 'fulltextindexed' in self.values:
-            UpdateFTIndexOp(self.session)
-            self.session.transaction_data.setdefault('fti_update_etypes',
-                                                     set()).add(etype)
+            UpdateFTIndexOp(session)
+            session.transaction_data.setdefault(
+                'fti_update_etypes', set()).add(etype)
+        elif 'fulltext_container' in self.values:
+            ftiupdates = session.transaction_data.setdefault(
+                'fti_update_etypes', set())
+            ftiupdates.add(etype)
+            ftiupdates.add(self.kobj[1])
+            UpdateFTIndexOp(session)
 
 
 class SourceDbCWConstraintAdd(hook.Operation):
--- a/server/sources/__init__.py	Thu Mar 04 18:02:33 2010 +0100
+++ b/server/sources/__init__.py	Thu Mar 04 18:04:26 2010 +0100
@@ -382,6 +382,22 @@
         """
         raise NotImplementedError()
 
+    def modified_entities(self, session, etypes, mtime):
+        """return a 2-uple:
+        * list of (etype, eid) of entities of the given types which have been
+          modified since the given timestamp (actually entities whose full text
+          index content has changed)
+        * list of (etype, eid) of entities of the given types which have been
+          deleted since the given timestamp
+        """
+        raise NotImplementedError()
+
+    def index_entity(self, session, entity):
+        """create an operation to [re]index textual content of the given entity
+        on commit
+        """
+        raise NotImplementedError()
+
     def fti_unindex_entity(self, session, eid):
         """remove text content for entity with the given eid from the full text
         index
@@ -393,16 +409,6 @@
         """
         raise NotImplementedError()
 
-    def modified_entities(self, session, etypes, mtime):
-        """return a 2-uple:
-        * list of (etype, eid) of entities of the given types which have been
-          modified since the given timestamp (actually entities whose full text
-          index content has changed)
-        * list of (etype, eid) of entities of the given types which have been
-          deleted since the given timestamp
-        """
-        raise NotImplementedError()
-
     # sql system source interface #############################################
 
     def sqlexec(self, session, sql, args=None):
--- a/server/sources/native.py	Thu Mar 04 18:02:33 2010 +0100
+++ b/server/sources/native.py	Thu Mar 04 18:04:26 2010 +0100
@@ -596,6 +596,9 @@
         return False
 
     def index_entity(self, session, entity):
+        """create an operation to [re]index textual content of the given entity
+        on commit
+        """
         FTIndexEntityOp(session, entity=entity)
 
     def fti_unindex_entity(self, session, eid):