|
2 | 2 | const { aql, query, db } = require("@arangodb"); |
3 | 3 | const users = require("@arangodb/users"); |
4 | 4 |
|
5 | | -const expirationTime = (336 * 60 * 60 * 1000) |
6 | | -const expired = [] |
| 5 | +const expirationTime = (4 * 60 * 60 * 1000) // 4 hours |
| 6 | +const expired = []; |
7 | 7 |
|
8 | 8 | let dbs = query` |
9 | | - FOR i IN aisisInstances |
10 | | - RETURN {key: i._key, dbName: i.dbName, timestamp: i.timestamp}` |
| 9 | + FOR i IN tutorialInstances |
| 10 | + RETURN {key: i._key, dbName: i.dbName, timestamp: i.timestamp, username: i.username}`; |
11 | 11 |
|
12 | 12 | dbs.toArray().map((d) => { |
13 | | - (Date.now() - expirationTime ) > d.timestamp ? removeDatabase(d.dbName, d.key) : '' |
| 13 | + (Date.now() - expirationTime ) > d.timestamp ? removeDatabase(d.dbName, d.key, d.username) : '' |
14 | 14 | }) |
15 | 15 |
|
16 | | -query` |
| 16 | +let cleanupCollection = query` |
17 | 17 | FOR key IN ${expired} |
18 | | -REMOVE { _key: key } IN aisisInstances |
19 | | -` |
| 18 | +FOR i IN tutorialInstances |
| 19 | +FILTER i._key |
| 20 | +INSERT {email: i.email, username: i.username, dbName: i.dbName} INTO expiredtutorialInstances |
| 21 | +REMOVE { _key: i._key } IN tutorialInstances`; |
20 | 22 |
|
21 | | -function removeDatabase(dbName, key) { |
22 | | - console.log(db._engineStats()) |
23 | | - db._dropDatabase(dbName) |
24 | | - expired.push(key) |
| 23 | +function removeDatabase(dbName, key, username) { |
| 24 | + console.log(db._engineStats()); |
| 25 | + users.remove(username); |
| 26 | + db._dropDatabase(dbName); |
| 27 | + expired.push(key); |
25 | 28 | } |
0 commit comments