diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-08-05 14:48:23 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-08-05 16:03:39 +0200 |
commit | c5c43c85d3c8ca8cf158f20a2433984872e54ce4 (patch) | |
tree | cbe363bafcba6057181329f2436bdb5414813c39 /connect-better-sqlite3.js | |
parent | dc7bc039757225106a7087821dc96d4ac3abe284 (diff) | |
download | server-c5c43c85d3c8ca8cf158f20a2433984872e54ce4.tar.gz |
Use sqlite in WAL mode.
Diffstat (limited to 'connect-better-sqlite3.js')
-rw-r--r-- | connect-better-sqlite3.js | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/connect-better-sqlite3.js b/connect-better-sqlite3.js index 2bfdb12..de858ed 100644 --- a/connect-better-sqlite3.js +++ b/connect-better-sqlite3.js @@ -29,14 +29,17 @@ module.exports = function (session) { db_path = (options.dir || '.') + '/' + db_path; let db = new SQLite(db_path, options.mode); + db.pragma("journal_mode = WAL"); + db.pragma("synchronous = NORMAL"); db.exec("CREATE TABLE IF NOT EXISTS "+table+" (sid PRIMARY KEY, expires INTEGER, sess TEXT)"); db.exec("DELETE FROM "+table+" WHERE "+now()+" > expires"); db.exec("VACUUM"); + db.exec("PRAGMA wal_checkpoint(TRUNCATE)"); this.sql_destroy = db.prepare("DELETE FROM "+table+" WHERE sid = ?"); this.sql_get = db.prepare("SELECT sess FROM "+table+" WHERE sid = ? AND ? <= expires"); this.sql_set = db.prepare("INSERT OR REPLACE INTO "+table+" VALUES (?,?,?)"); - this.sql_touch = db.prepare("UPDATE "+table+" SET expires = ? WHERE sid = ? AND ? <= expires"); + this.sql_touch = db.prepare("UPDATE "+table+" SET expires = ? WHERE sid = ? AND expires < ?"); } destroy(sid, cb = noop) { @@ -77,7 +80,8 @@ module.exports = function (session) { try { if (sess && sess.cookie && sess.cookie.expires) { let expires = seconds(sess.cookie.expires); - this.sql_touch.run(expires, sid, now()); + let limit = expires - 3600; + this.sql_touch.run(expires, sid, limit); cb(null); } else { cb(null); |