MCPcopy Create free account
hub / github.com/aaPanel/BaoTa / sess_expire_sql

Method sess_expire_sql

script/task_script_extension.py:273–297  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

271 self.write_log(str(ex))
272
273 def sess_expire_sql(self):
274 try:
275 import sqlite3
276 self.write_log("启动session过期处理")
277 db_file = os.path.join(PANEL_PATH, "data/db/session.db")
278 if not os.path.exists(db_file):
279 return
280 size = os.path.getsize(db_file)
281 if size < 1024 * 1024 * 25: # 不足 10M 不用清理
282 return
283 elif size > 1024 * 1024 * 100: # 大于 100M 删除所有数据
284 public.clear_sql_session()
285 return
286 conn = sqlite3.connect(db_file)
287 cur = conn.cursor()
288 expiry_time = (datetime.now(tz=timezone.utc)- timedelta(days=1)).strftime("%Y-%m-%d %H:%M:%S.%f")
289 res = cur.execute("DELETE FROM sessions WHERE expiry < ?", (expiry_time,))
290 self.write_log("session过期处理: 删除了{}条数据".format(res.rowcount))
291 res = cur.execute("DELETE FROM sessions WHERE LENGTH(`data`) < ?", (200,))
292 self.write_log("session过期处理: 删除了{}条空值数据".format(res.rowcount))
293 cur.close()
294 conn.commit()
295 conn.close()
296 except Exception as e:
297 self.write_log(str(e))
298
299 def refresh_domain_cache(self):
300 ''&#x27;

Callers 1

sess_expireMethod · 0.95

Calls 9

write_logMethod · 0.95
nowMethod · 0.80
joinMethod · 0.45
existsMethod · 0.45
connectMethod · 0.45
executeMethod · 0.45
formatMethod · 0.45
closeMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected