forked from cory/tildefriends
Enumerate apps without walking all DB keys.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3768 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
1ae9aaf752
commit
4637509b3d
26
core/core.js
26
core/core.js
@ -193,12 +193,17 @@ async function getProcessBlob(blobId, key, options) {
|
||||
'getUser': getUser.bind(null, process, process),
|
||||
'user': getUser(process, process),
|
||||
'apps': function() {
|
||||
var apps = process.credentials &&
|
||||
if (process.credentials &&
|
||||
process.credentials.session &&
|
||||
process.credentials.session.name ?
|
||||
new Database(process.credentials.session.name).getLike('path:%') :
|
||||
{};
|
||||
return Object.fromEntries(Object.keys(apps).map(key => [key.substring(5), apps[key]]));
|
||||
process.credentials.session.name) {
|
||||
var db = new Database(process.credentials.session.name);
|
||||
try {
|
||||
var names = JSON.parse(db.get('apps'));
|
||||
return Object.fromEntries(names.map(name => [name, db.get('path:' + name)]));
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
return {};
|
||||
},
|
||||
}
|
||||
};
|
||||
@ -478,7 +483,16 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
return;
|
||||
}
|
||||
var database = new Database(user);
|
||||
await database.set('path:' + app, newBlobId);
|
||||
var apps = new Set();
|
||||
try {
|
||||
apps = new Set(JSON.parse(database.get('apps')));
|
||||
} catch {
|
||||
}
|
||||
if (!apps.has(app)) {
|
||||
apps.add(app);
|
||||
database.set('apps', JSON.stringify([...apps]));
|
||||
}
|
||||
database.set('path:' + app, newBlobId);
|
||||
}
|
||||
|
||||
response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
|
||||
|
Loading…
Reference in New Issue
Block a user