-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbase.js
More file actions
50 lines (45 loc) · 1.13 KB
/
base.js
File metadata and controls
50 lines (45 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const { Deta } = require ('deta');
const deta = Deta(process.env.DETA_PROJECT_KEY);
/*
repoDB schema:
{
"key": str, // repo id
"name": str, // repo name
"owner": str, // repo owner
"installation_id": int // installation id
}
*/
const repoDB = deta.Base('repos');
/*
cachedb schema:
{
"key": str, // randomly generated
"repo": int, // repo_id, foreign ref key in repoDB
"file": str, // file name
"last_hit": int // timestamp of last cache hit in epochs,
"number_of_hits": int // number of cache hits
}
*/
const cacheDB = deta.Base('cache');
const putItems = async (db, items) => {
const l = items.length;
if (items.length <= 24) {
return db.putMany(items);
}
// putMany op supports only 24 items max
// send in batches of 24 items if more than 24 items
let start = 0, end = 0;
while(end != l){
end += 24;
if (end > l){
end = l;
}
try {
db.putMany(items.slice(start, end));
} catch(err){
return Promise.reject(err);
}
start = end;
}
};
module.exports = { repoDB, cacheDB, putItems };