1 | from MaKaC.common import DBMgr |
---|
2 | from MaKaC.webinterface.session.sessionManagement import getSessionManager |
---|
3 | |
---|
4 | def deleteSessions(sm,todelete): |
---|
5 | done = 0 |
---|
6 | for key in todelete : |
---|
7 | sm.delete_session(key) |
---|
8 | done+=1 |
---|
9 | try: |
---|
10 | DBMgr.getInstance().commit() |
---|
11 | except: |
---|
12 | DBMgr.getInstance().sync() |
---|
13 | print "deleted %s sessions" % (len(todelete)) |
---|
14 | |
---|
15 | DBMgr.getInstance().startRequest() |
---|
16 | websessionDelay = float(24 * 3600) |
---|
17 | sm = getSessionManager() |
---|
18 | print "ok got session manager" |
---|
19 | keys = sm.keys() |
---|
20 | print "ok got keys" |
---|
21 | done = 0 |
---|
22 | fresh = 0 |
---|
23 | todelete = [] |
---|
24 | batchsize = 1000 |
---|
25 | |
---|
26 | print "start deleting" |
---|
27 | for key in keys: |
---|
28 | value = sm[key] |
---|
29 | try: |
---|
30 | if value.get_access_age() > websessionDelay: |
---|
31 | todelete.append(key) |
---|
32 | else: |
---|
33 | fresh+=1 |
---|
34 | if (fresh%batchsize)==0: |
---|
35 | print "too fresh %s sessions" % (fresh) |
---|
36 | except: |
---|
37 | print "cannot delete %s" % key |
---|
38 | if len(todelete) >= batchsize : |
---|
39 | deleteSessions(sm,todelete) |
---|
40 | todelete = [] |
---|
41 | |
---|
42 | if len(todelete) > 0 : |
---|
43 | deleteSessions(sm,todelete) |
---|
44 | |
---|
45 | print "too fresh %s sessions" % (fresh) |
---|
46 | |
---|
47 | DBMgr.getInstance().endRequest() |
---|