server/querier.py
changeset 4954 96f67c5be0e6
parent 4953 c8c0e10dbd97
child 4955 8ddd5e938804
equal deleted inserted replaced
4953:c8c0e10dbd97 4954:96f67c5be0e6
   186     def preprocess(self, union, security=True):
   186     def preprocess(self, union, security=True):
   187         """insert security when necessary then annotate rql st for sql generation
   187         """insert security when necessary then annotate rql st for sql generation
   188 
   188 
   189         return rqlst to actually execute
   189         return rqlst to actually execute
   190         """
   190         """
   191         noinvariant = set()
   191         cached = None
   192         if security and self.session.read_security:
   192         if security and self.session.read_security:
   193             # ensure security is turned of when security is inserted,
   193             # ensure security is turned of when security is inserted,
   194             # else we may loop for ever...
   194             # else we may loop for ever...
   195             with security_enabled(self.session, read=False):
   195             if self.session.transaction_data.get('security-rqlst-cache'):
   196                 self._insert_security(union, noinvariant)
   196                 key = self.cache_key
   197         self.rqlhelper.simplify(union)
   197             else:
   198         self.sqlannotate(union)
   198                 key = None
   199         set_qdata(self.schema.rschema, union, noinvariant)
   199             if key is not None and key in self.session.transaction_data:
       
   200                 cachedunion, args = self.session.transaction_data[key]
       
   201                 union.children[:] = []
       
   202                 for select in cachedunion.children:
       
   203                     union.append(select)
       
   204                 union.has_text_query = cachedunion.has_text_query
       
   205                 args.update(self.args)
       
   206                 self.args = args
       
   207                 cached = True
       
   208             else:
       
   209                 noinvariant = set()
       
   210                 with security_enabled(self.session, read=False):
       
   211                     self._insert_security(union, noinvariant)
       
   212                 if key is not None:
       
   213                     self.session.transaction_data[key] = (union, self.args)
       
   214         else:
       
   215             noinvariant = ()
       
   216         if cached is None:
       
   217             self.rqlhelper.simplify(union)
       
   218             self.sqlannotate(union)
       
   219             set_qdata(self.schema.rschema, union, noinvariant)
   200         if union.has_text_query:
   220         if union.has_text_query:
   201             self.cache_key = None
   221             self.cache_key = None
   202 
   222 
   203     def _insert_security(self, union, noinvariant):
   223     def _insert_security(self, union, noinvariant):
   204         for select in union.children[:]:
   224         for select in union.children[:]: