@boxyhq/saml-jackson 0.1.5-beta.139 → 0.1.5-beta.140
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/db/db.test.js
CHANGED
@@ -224,7 +224,7 @@ t.test('dbs', ({ end }) => {
|
|
224
224
|
}
|
225
225
|
|
226
226
|
await new Promise((resolve) =>
|
227
|
-
setTimeout(resolve, (
|
227
|
+
setTimeout(resolve, (2*ttl + 0.5) * 1000)
|
228
228
|
);
|
229
229
|
|
230
230
|
const ret1 = await ttlStore.get(record1.id);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
const EntitySchema = require('typeorm').EntitySchema;
|
2
|
+
const JacksonTTL = require('../model/JacksonTTL.js');
|
3
|
+
|
4
|
+
module.exports = new EntitySchema({
|
5
|
+
name: 'JacksonTTL',
|
6
|
+
target: JacksonTTL,
|
7
|
+
columns: {
|
8
|
+
key: {
|
9
|
+
primary: true,
|
10
|
+
type: 'varchar',
|
11
|
+
length: 1500,
|
12
|
+
},
|
13
|
+
expiresAt: {
|
14
|
+
type: 'bigint',
|
15
|
+
},
|
16
|
+
},
|
17
|
+
indices: [
|
18
|
+
{
|
19
|
+
name: '_jackson_ttl_expires_at',
|
20
|
+
columns: ['expiresAt'],
|
21
|
+
},
|
22
|
+
],
|
23
|
+
});
|
package/src/db/sql/sql.js
CHANGED
@@ -2,6 +2,7 @@ require('reflect-metadata');
|
|
2
2
|
const typeorm = require('typeorm');
|
3
3
|
const JacksonStore = require('./model/JacksonStore.js');
|
4
4
|
const JacksonIndex = require('./model/JacksonIndex.js');
|
5
|
+
const JacksonTTL = require('./model/JacksonTTL.js');
|
5
6
|
|
6
7
|
const dbutils = require('../utils.js');
|
7
8
|
|
@@ -20,6 +21,7 @@ class Sql {
|
|
20
21
|
entities: [
|
21
22
|
require('./entity/JacksonStore.js')(options.type),
|
22
23
|
require('./entity/JacksonIndex.js'),
|
24
|
+
require('./entity/JacksonTTL.js'),
|
23
25
|
],
|
24
26
|
});
|
25
27
|
|
@@ -33,22 +35,29 @@ class Sql {
|
|
33
35
|
|
34
36
|
this.storeRepository = this.connection.getRepository(JacksonStore);
|
35
37
|
this.indexRepository = this.connection.getRepository(JacksonIndex);
|
38
|
+
this.ttlRepository = this.connection.getRepository(JacksonTTL);
|
36
39
|
|
37
40
|
if (options.ttl && options.limit) {
|
38
41
|
this.ttlCleanup = async () => {
|
39
42
|
const now = Date.now();
|
40
43
|
|
41
44
|
while (true) {
|
42
|
-
const ids = await this.
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
const ids = await this.ttlRepository
|
46
|
+
.createQueryBuilder('jackson_ttl')
|
47
|
+
.limit(options.limit)
|
48
|
+
.where('jackson_ttl.expiresAt <= :expiresAt', { expiresAt: now })
|
49
|
+
.getMany();
|
46
50
|
|
47
51
|
if (ids.length <= 0) {
|
48
52
|
break;
|
49
53
|
}
|
50
54
|
|
55
|
+
const delIds = ids.map((id) => {
|
56
|
+
return id.key;
|
57
|
+
});
|
58
|
+
|
51
59
|
await this.storeRepository.remove(ids);
|
60
|
+
await this.ttlRepository.delete(delIds);
|
52
61
|
}
|
53
62
|
|
54
63
|
this.timerId = setTimeout(this.ttlCleanup, options.ttl * 1000);
|
@@ -99,13 +108,15 @@ class Sql {
|
|
99
108
|
|
100
109
|
async put(namespace, key, val, ttl = 0, ...indexes) {
|
101
110
|
await this.connection.transaction(async (transactionalEntityManager) => {
|
102
|
-
const
|
103
|
-
|
104
|
-
JSON.stringify(val),
|
105
|
-
ttl > 0 ? Date.now() + ttl * 1000 : null
|
106
|
-
);
|
111
|
+
const dbKey = dbutils.key(namespace, key);
|
112
|
+
const store = new JacksonStore(dbKey, JSON.stringify(val));
|
107
113
|
await transactionalEntityManager.save(store);
|
108
114
|
|
115
|
+
if (ttl) {
|
116
|
+
const ttlRec = new JacksonTTL(dbKey, Date.now() + ttl * 1000);
|
117
|
+
await transactionalEntityManager.save(ttlRec);
|
118
|
+
}
|
119
|
+
|
109
120
|
// no ttl support for secondary indexes
|
110
121
|
for (const idx of indexes || []) {
|
111
122
|
const key = dbutils.keyForIndex(namespace, idx);
|