mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-25 15:37:12 +00:00
perf: multiple kv keys
This commit is contained in:
@@ -32,6 +32,29 @@ class DBKVService extends BaseService {
|
||||
app = await get_app({ uid: app_uid });
|
||||
}
|
||||
|
||||
if ( Array.isArray(key) ) {
|
||||
const keys = key;
|
||||
const key_hashes = keys.map(key => this.modules.murmurhash.v3(key));
|
||||
const rows = app ? await this.db.read(
|
||||
`SELECT kkey, value FROM kv WHERE user_id=? AND app=? AND kkey_hash IN (?)`,
|
||||
[ user.id, app.uid, key_hashes ]
|
||||
) : await this.db.read(
|
||||
`SELECT kkey, value FROM kv WHERE user_id=? AND (app IS NULL OR app = 'global') AND kkey_hash IN (?)`,
|
||||
[ user.id, key_hashes ]
|
||||
);
|
||||
|
||||
const kv = {};
|
||||
rows.forEach(row => {
|
||||
row.value = this.db.case({
|
||||
mysql: () => row.value,
|
||||
otherwise: () => JSON.parse(row.value ?? 'null'),
|
||||
})();
|
||||
kv[row.kkey] = row.value;
|
||||
});
|
||||
|
||||
return keys.map(key => kv[key]);
|
||||
}
|
||||
|
||||
const key_hash = this.modules.murmurhash.v3(key);
|
||||
const kv = app ? await this.db.read(
|
||||
`SELECT * FROM kv WHERE user_id=? AND app=? AND kkey_hash=? LIMIT 1`,
|
||||
|
||||
@@ -111,7 +111,7 @@ module.exports = {
|
||||
get: {
|
||||
description: 'Get a value by key.',
|
||||
parameters: {
|
||||
key: { type: 'string', required: true },
|
||||
key: { type: 'json', required: true },
|
||||
app_uid: { type: 'string', optional: true },
|
||||
},
|
||||
result: { type: 'json' },
|
||||
|
||||
Reference in New Issue
Block a user