Skip to content

Commit 7744966

Browse files
committed
Add comments
1 parent 85bf84d commit 7744966

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/storage/providers/SQLiteProvider.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ 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.
110111
if (keys.length <= 500) {
111112
const placeholders = keys.map(() => '?').join(',');
112113
const command = `SELECT record_key, valueJSON FROM keyvaluepairs WHERE record_key IN (${placeholders});`;
@@ -117,10 +118,10 @@ const provider: StorageProvider<NitroSQLiteConnection | undefined> = {
117118
});
118119
}
119120

121+
// For a large number of keys, it becomes more performant if we insert the keys into a temporary table and perform a join.
120122
// FIXME: Not working because of "-" apparently.
121123
// const tableName = `temp_multiGet_${Str.guid()}`;
122124
const tableName = `temp_multiGet_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
123-
124125
return provider.store
125126
.executeAsync(`CREATE TEMP TABLE ${tableName} (record_key TEXT PRIMARY KEY);`)
126127
.then(() => {
@@ -139,8 +140,8 @@ const provider: StorageProvider<NitroSQLiteConnection | undefined> = {
139140

140141
return provider.store.executeAsync<OnyxSQLiteKeyValuePair>(
141142
`SELECT k.record_key, k.valueJSON
142-
FROM keyvaluepairs AS k
143-
INNER JOIN ${tableName} AS t ON k.record_key = t.record_key;`,
143+
FROM keyvaluepairs AS k
144+
INNER JOIN ${tableName} AS t ON k.record_key = t.record_key;`,
144145
);
145146
})
146147
.then(({rows}) => {
@@ -150,7 +151,6 @@ const provider: StorageProvider<NitroSQLiteConnection | undefined> = {
150151
return result ?? [];
151152
})
152153
.catch((error) => {
153-
console.error('[SQLiteProvider] Error in multiGet:', error);
154154
provider.store?.executeAsync(`DROP TABLE IF EXISTS ${tableName};`);
155155
throw error;
156156
});

0 commit comments

Comments
 (0)