[web] dont attempt to update last login time on ldap users, avoiding spurious tb in logs (closes #914464) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 26 May 2010 12:31:40 +0200
branchstable
changeset 5587 72679e450f6d
parent 5586 aabe082fee02
child 5588 377c9adfe81e
[web] dont attempt to update last login time on ldap users, avoiding spurious tb in logs (closes #914464)
server/repository.py
web/application.py
--- a/server/repository.py	Wed May 26 12:31:39 2010 +0200
+++ b/server/repository.py	Wed May 26 12:31:40 2010 +0200
@@ -25,14 +25,14 @@
   point to a cubicweb instance.
 * handles session management
 * provides method for pyro registration, to call if pyro is enabled
-
+"""
 
-"""
 from __future__ import with_statement
 
 __docformat__ = "restructuredtext en"
 
 import sys
+import threading
 import Queue
 from os.path import join
 from datetime import datetime
@@ -315,7 +315,6 @@
     def pinfo(self):
         # XXX: session.pool is accessed from a local storage, would be interesting
         #      to see if there is a pool set in any thread specific data)
-        import threading
         return '%s: %s (%s)' % (self._available_pools.qsize(),
                                 ','.join(session.user.login for session in self._sessions.values()
                                          if session.pool),
@@ -362,28 +361,6 @@
         except ZeroDivisionError:
             pass
 
-    def stats(self): # XXX restrict to managers session?
-        import threading
-        results = {}
-        querier = self.querier
-        source = self.system_source
-        for size, maxsize, hits, misses, title in (
-            (len(querier._rql_cache), self.config['rql-cache-size'],
-            querier.cache_hit, querier.cache_miss, 'rqlt_st'),
-            (len(source._cache), self.config['rql-cache-size'],
-            source.cache_hit, source.cache_miss, 'sql'),
-            ):
-            results['%s_cache_size' % title] =  '%s / %s' % (size, maxsize)
-            results['%s_cache_hit' % title] =  hits
-            results['%s_cache_miss' % title] = misses
-            results['%s_cache_hit_percent' % title] = (hits * 100) / (hits + misses)
-        results['sql_no_cache'] = self.system_source.no_cache
-        results['nb_open_sessions'] = len(self._sessions)
-        results['nb_active_threads'] = threading.activeCount()
-        results['looping_tasks'] = ', '.join(str(t) for t in self._looping_tasks)
-        results['available_pools'] = self._available_pools.qsize()
-        return results
-
     def _login_from_email(self, login):
         session = self.internal_session()
         try:
@@ -433,6 +410,27 @@
 
     # public (dbapi) interface ################################################
 
+    def stats(self): # XXX restrict to managers session?
+        results = {}
+        querier = self.querier
+        source = self.system_source
+        for size, maxsize, hits, misses, title in (
+            (len(querier._rql_cache), self.config['rql-cache-size'],
+            querier.cache_hit, querier.cache_miss, 'rqlt_st'),
+            (len(source._cache), self.config['rql-cache-size'],
+            source.cache_hit, source.cache_miss, 'sql'),
+            ):
+            results['%s_cache_size' % title] =  '%s / %s' % (size, maxsize)
+            results['%s_cache_hit' % title] =  hits
+            results['%s_cache_miss' % title] = misses
+            results['%s_cache_hit_percent' % title] = (hits * 100) / (hits + misses)
+        results['sql_no_cache'] = self.system_source.no_cache
+        results['nb_open_sessions'] = len(self._sessions)
+        results['nb_active_threads'] = threading.activeCount()
+        results['looping_tasks'] = ', '.join(str(t) for t in self._looping_tasks)
+        results['available_pools'] = self._available_pools.qsize()
+        return results
+
     def get_schema(self):
         """return the instance schema. This is a public method, not
         requiring a session id
--- a/web/application.py	Wed May 26 12:31:39 2010 +0200
+++ b/web/application.py	Wed May 26 12:31:40 2010 +0200
@@ -233,12 +233,15 @@
         return session
 
     def _update_last_login_time(self, req):
+        # XXX should properly detect missing permission / non writeable source
+        # and avoid "except (RepositoryError, Unauthorized)" below
+        if req.user.metainformation()['source']['adapter'] == 'ldapuser':
+            return
         try:
             req.execute('SET X last_login_time NOW WHERE X eid %(x)s',
                         {'x' : req.user.eid})
             req.cnx.commit()
         except (RepositoryError, Unauthorized):
-            # ldap user are not writeable for instance
             req.cnx.rollback()
         except:
             req.cnx.rollback()