SQL improvement
- Improved SQL query for periodic clearing of old/unauthorised data
This commit is contained in:
parent
0bff57c28b
commit
121979b696
@ -479,27 +479,28 @@ DB.deleteData = function (snID, vectorClock) {
|
|||||||
DB.clearAuthorisedAppData = function (snID, app, adminID, subAdmins, timestamp) {
|
DB.clearAuthorisedAppData = function (snID, app, adminID, subAdmins, timestamp) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let statement = "DELETE FROM _" + snID +
|
let statement = "DELETE FROM _" + snID +
|
||||||
" WHERE ( " + H_struct.TIME + "<? AND " +
|
" WHERE ( " +
|
||||||
H_struct.APPLICATION + "=? AND " +
|
H_struct.TIME + " < ? AND " + //data before deleteDelay (ie, 7 days ago)
|
||||||
T_struct.TAG + " IS NULL )" +
|
H_struct.APPLICATION + " = ? AND " + //data of this app
|
||||||
(subAdmins.length ? " AND ( " +
|
T_struct.TAG + " IS NULL " + //tag field is NULL
|
||||||
H_struct.RECEIVER_ID + " != ? OR " +
|
") AND ( " +
|
||||||
H_struct.SENDER_ID + " NOT IN (" + subAdmins.map(a => "?").join(", ") + ") )" :
|
H_struct.RECEIVER_ID + " != ? OR " + //receiver is not admin
|
||||||
"");
|
H_struct.SENDER_ID + " NOT IN (?) " + //sender is not subAdmin
|
||||||
queryResolve(statement, [timestamp, app, adminID].concat(subAdmins))
|
")";
|
||||||
|
|
||||||
|
queryResolve(statement, [timestamp, app, adminID, subAdmins])
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
DB.clearUnauthorisedAppData = function (snID, appList, timestamp) {
|
DB.clearUnauthorisedAppData = function (snID, authorisedAppList, timestamp) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let statement = "DELETE FROM _" + snID +
|
let statement = "DELETE FROM _" + snID +
|
||||||
" WHERE " + H_struct.TIME + "<?" +
|
" WHERE " + H_struct.TIME + " < ? AND" + //data before deleteDelay (ie, 7 days ago)
|
||||||
(appList.length ? " AND " +
|
H_struct.APPLICATION + " NOT IN (?)" //app not authorised
|
||||||
H_struct.APPLICATION + " NOT IN (" + appList.map(a => "?").join(", ") + ")" :
|
|
||||||
"");
|
queryResolve(statement, [timestamp, authorisedAppList])
|
||||||
queryResolve(statement, [timestamp].concat(appList))
|
|
||||||
.then(result => resolve(result))
|
.then(result => resolve(result))
|
||||||
.catch(error => reject(error));
|
.catch(error => reject(error));
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user