Skip to content

Commit 0f17bdb

Browse files
committed
Revert multiGet changes
1 parent 0e80d49 commit 0f17bdb

1 file changed

Lines changed: 7 additions & 47 deletions

File tree

lib/storage/providers/SQLiteProvider.ts

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -107,53 +107,13 @@ const provider: StorageProvider<NitroSQLiteConnection | undefined> = {
107107
throw new Error('Store is not initialized!');
108108
}
109109

110-
// For a small number of keys, it's more efficient to just use a single query with multiple placeholders.
111-
if (keys.length <= 500) {
112-
const placeholders = keys.map(() => '?').join(',');
113-
const command = `SELECT record_key, valueJSON FROM keyvaluepairs WHERE record_key IN (${placeholders});`;
114-
return provider.store.executeAsync<OnyxSQLiteKeyValuePair>(command, keys).then(({rows}) => {
115-
// eslint-disable-next-line no-underscore-dangle
116-
const result = rows?._array.map<StorageKeyValuePair>((row) => [row.record_key, JSON.parse(row.valueJSON)]);
117-
return result ?? [];
118-
});
119-
}
120-
121-
// For a large number of keys, it becomes more performant if we insert the keys into a temporary table and perform a join.
122-
// FIXME: Not working because of "-" apparently.
123-
// const tableName = `temp_multiGet_${Str.guid()}`;
124-
const tableName = `temp_multiGet_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
125-
return provider.store
126-
.executeAsync(`CREATE TEMP TABLE ${tableName} (record_key TEXT PRIMARY KEY);`)
127-
.then(() => {
128-
if (!provider.store) {
129-
throw new Error('Store is not initialized!');
130-
}
131-
132-
const insertQuery = `INSERT INTO ${tableName} (record_key) VALUES (?);`;
133-
const insertParams = keys.map((key) => [key]);
134-
return provider.store.executeBatchAsync([{query: insertQuery, params: insertParams}]);
135-
})
136-
.then(() => {
137-
if (!provider.store) {
138-
throw new Error('Store is not initialized!');
139-
}
140-
141-
return provider.store.executeAsync<OnyxSQLiteKeyValuePair>(
142-
`SELECT k.record_key, k.valueJSON
143-
FROM keyvaluepairs AS k
144-
INNER JOIN ${tableName} AS t ON k.record_key = t.record_key;`,
145-
);
146-
})
147-
.then(({rows}) => {
148-
// eslint-disable-next-line no-underscore-dangle
149-
const result = rows?._array.map<StorageKeyValuePair>((row) => [row.record_key, JSON.parse(row.valueJSON)]);
150-
151-
return result ?? [];
152-
})
153-
.finally(() => {
154-
// Drops the temporary table to free up resources.
155-
provider.store?.executeAsync(`DROP TABLE IF EXISTS ${tableName};`);
156-
});
110+
const placeholders = keys.map(() => '?').join(',');
111+
const command = `SELECT record_key, valueJSON FROM keyvaluepairs WHERE record_key IN (${placeholders});`;
112+
return provider.store.executeAsync<OnyxSQLiteKeyValuePair>(command, keys).then(({rows}) => {
113+
// eslint-disable-next-line no-underscore-dangle
114+
const result = rows?._array.map((row) => [row.record_key, JSON.parse(row.valueJSON)]);
115+
return (result ?? []) as StorageKeyValuePair[];
116+
});
157117
},
158118
setItem(key, value) {
159119
if (!provider.store) {

0 commit comments

Comments
 (0)