db/SessionStore.js: do not migrate to Promises. Make optional all(), clear() and length()
1. This module was not migrated to Promises, because it is only used via express-session, which can't actually use promises anyway. 2. all(), clear() and length() depend on the presence of the `db.forEach()` function, which in ueberdb2 doesn't even exist. Fortunately those three methods are optional, so I made their existence conditional on the presence of `db.forEach`. 3. in SessionStore.clear(), replaced a call to db.db.remove() with db.remove()
This commit is contained in:
parent
630af9af7d
commit
583ea92aaf
1 changed files with 43 additions and 33 deletions
|
@ -2,6 +2,9 @@
|
|||
* Stores session data in the database
|
||||
* Source; https://github.com/edy-b/SciFlowWriter/blob/develop/available_plugins/ep_sciflowwriter/db/DirtyStore.js
|
||||
* This is not used for authors that are created via the API at current
|
||||
*
|
||||
* RPB: this module was not migrated to Promises, because it is only used via
|
||||
* express-session, which can't actually use promises anyway.
|
||||
*/
|
||||
|
||||
var Store = require('ep_etherpad-lite/node_modules/express-session').Store,
|
||||
|
@ -50,39 +53,46 @@ SessionStore.prototype.destroy = function(sid, fn) {
|
|||
}
|
||||
};
|
||||
|
||||
SessionStore.prototype.all = function(fn) {
|
||||
messageLogger.debug('ALL');
|
||||
/*
|
||||
* RPB: the following methods are optional requirements for a compatible session
|
||||
* store for express-session, but in any case appear to depend on a
|
||||
* non-existent feature of ueberdb2
|
||||
*/
|
||||
if (db.forEach) {
|
||||
SessionStore.prototype.all = function(fn) {
|
||||
messageLogger.debug('ALL');
|
||||
|
||||
var sessions = [];
|
||||
var sessions = [];
|
||||
|
||||
db.forEach(function(key, value) {
|
||||
if (key.substr(0,15) === "sessionstorage:") {
|
||||
sessions.push(value);
|
||||
}
|
||||
});
|
||||
fn(null, sessions);
|
||||
};
|
||||
|
||||
SessionStore.prototype.clear = function(fn) {
|
||||
messageLogger.debug('CLEAR');
|
||||
|
||||
db.forEach(function(key, value) {
|
||||
if (key.substr(0,15) === "sessionstorage:") {
|
||||
db.db.remove("session:" + key);
|
||||
}
|
||||
});
|
||||
if (fn) fn();
|
||||
};
|
||||
|
||||
SessionStore.prototype.length = function(fn) {
|
||||
messageLogger.debug('LENGTH');
|
||||
|
||||
var i = 0;
|
||||
|
||||
db.forEach(function(key, value) {
|
||||
if (key.substr(0,15) === "sessionstorage:") {
|
||||
i++;
|
||||
}
|
||||
});
|
||||
fn(null, i);
|
||||
db.forEach(function(key, value) {
|
||||
if (key.substr(0,15) === "sessionstorage:") {
|
||||
sessions.push(value);
|
||||
}
|
||||
});
|
||||
fn(null, sessions);
|
||||
};
|
||||
|
||||
SessionStore.prototype.clear = function(fn) {
|
||||
messageLogger.debug('CLEAR');
|
||||
|
||||
db.forEach(function(key, value) {
|
||||
if (key.substr(0,15) === "sessionstorage:") {
|
||||
db.remove("session:" + key);
|
||||
}
|
||||
});
|
||||
if (fn) fn();
|
||||
};
|
||||
|
||||
SessionStore.prototype.length = function(fn) {
|
||||
messageLogger.debug('LENGTH');
|
||||
|
||||
var i = 0;
|
||||
|
||||
db.forEach(function(key, value) {
|
||||
if (key.substr(0,15) === "sessionstorage:") {
|
||||
i++;
|
||||
}
|
||||
});
|
||||
fn(null, i);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue