Browse Source

HUE-87. Merging IP and last access time maps.

vinithra 15 years ago
parent
commit
ad0ba987f9
2 changed files with 7 additions and 9 deletions
  1. 2 2
      desktop/core/src/desktop/auth/views.py
  2. 5 7
      desktop/core/src/desktop/log/access.py

+ 2 - 2
desktop/core/src/desktop/auth/views.py

@@ -28,7 +28,7 @@ from django.http import HttpResponseRedirect
 from desktop.auth.backend import AllowFirstUserDjangoBackend
 from desktop.lib.django_util import render_json, render
 from desktop.lib.django_util import login_notrequired
-from desktop.log.access import access_warn, remote_ip_map, recent_access_time_map
+from desktop.log.access import access_warn, last_access_map
 
 LOG = logging.getLogger(__name__)
 
@@ -72,7 +72,7 @@ def get_current_users():
         userobj = User.objects.get(pk=uid)
       except User.DoesNotExist:
         LOG.debug("User with id=%d does not exist" % uid)
-      current_users[userobj] = {'ip':remote_ip_map.get(userobj.username, ''), 'time':recent_access_time_map.get(userobj.username, '')}
+      current_users[userobj] = last_access_map.get(userobj.username, { })
 
   return current_users
 

+ 5 - 7
desktop/core/src/desktop/log/access.py

@@ -52,11 +52,9 @@ recent_access_map = { }
 _recent_access_map_lk = threading.Lock()
 _per_user_lk = { }      # Indexed by username
 
-# Store a map of usernames and their IP addresses
-remote_ip_map = { }
-
-# Store a map of usernames and last access times
-recent_access_time_map = { }
+# Store a map of usernames and a dictionary of
+# their IP addresses and last access times
+last_access_map = { }
 
 # Max number of records per user per view to keep
 _USER_ACCESS_HISTORY_SIZE = desktop.conf.USER_ACCESS_HISTORY_SIZE.get()
@@ -104,8 +102,8 @@ class AccessInfo(dict):
         _per_user_lk[user] = threading.Lock()
         recent_access_map[user] = app_dict
         # Update the IP address and last access time of the user
-        remote_ip_map[user] = self['remote_ip']
-        recent_access_time_map[user] = self['time']
+        last_access_map[user] = {'ip':self['remote_ip'],
+                                 'time':self['time']}
       finally:
         _recent_access_map_lk.release()