@bobfrankston/mailx-store 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db.js +13 -4
- package/package.json +1 -1
package/db.js
CHANGED
|
@@ -2337,10 +2337,19 @@ export class MailxDB {
|
|
|
2337
2337
|
scopeWhere += " AND " + extraWhere.join(" AND ");
|
|
2338
2338
|
scopeParams.push(...extraParams);
|
|
2339
2339
|
}
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2340
|
+
// Cap COUNT at 1001 — a bare `SELECT COUNT(*)` on FTS5 has to
|
|
2341
|
+
// enumerate every match, which for a common term ("ieee", "the")
|
|
2342
|
+
// can be tens of thousands of rows and several seconds. We never
|
|
2343
|
+
// paginate past a few hundred in the UI anyway, so capping the
|
|
2344
|
+
// count is invisible to the user and turns search from
|
|
2345
|
+
// multi-second to sub-second. UI shows "1000+" when cnt === 1001.
|
|
2346
|
+
const countRow = this.db.prepare(`SELECT COUNT(*) as cnt FROM (
|
|
2347
|
+
SELECT 1 FROM messages m
|
|
2348
|
+
JOIN messages_fts fts ON m.id = fts.rowid
|
|
2349
|
+
LEFT JOIN folders f ON f.id = m.folder_id AND f.account_id = m.account_id
|
|
2350
|
+
WHERE messages_fts MATCH ?${scopeWhere}
|
|
2351
|
+
LIMIT 1001
|
|
2352
|
+
)`).get(ftsQuery, ...scopeParams);
|
|
2344
2353
|
const total = countRow?.cnt || 0;
|
|
2345
2354
|
const rows = this.db.prepare(`SELECT m.*, f.name AS folder_name FROM messages m
|
|
2346
2355
|
JOIN messages_fts fts ON m.id = fts.rowid
|