@remit/drizzle-service 0.0.36 → 0.0.37
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/package.json
CHANGED
|
@@ -10,7 +10,10 @@ import {
|
|
|
10
10
|
LIVE_TOTALS,
|
|
11
11
|
totalRows,
|
|
12
12
|
} from "./category-fixture.js";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
DrizzleThreadMessageRepository,
|
|
15
|
+
THREAD_SEARCH_MAX_LIMIT,
|
|
16
|
+
} from "./thread-message.js";
|
|
14
17
|
|
|
15
18
|
// The thread-message repo on sqlite (RFC 036 D1): CRUD, keyset pagination, and
|
|
16
19
|
// text search — the FTS5 trigram index for terms of three characters or more
|
|
@@ -163,12 +166,9 @@ describe("DrizzleThreadMessageRepository (sqlite)", () => {
|
|
|
163
166
|
});
|
|
164
167
|
|
|
165
168
|
test("countByMailbox counts matches under the same predicate", async () => {
|
|
166
|
-
const n = await repo.countByMailbox(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
{ subject: "invoice" },
|
|
170
|
-
{ limit: 100 },
|
|
171
|
-
);
|
|
169
|
+
const n = await repo.countByMailbox(ACCOUNT, MAILBOX, {
|
|
170
|
+
subject: "invoice",
|
|
171
|
+
});
|
|
172
172
|
assert.ok(n >= 1);
|
|
173
173
|
});
|
|
174
174
|
|
|
@@ -754,9 +754,6 @@ describe("DrizzleThreadMessageRepository (sqlite)", () => {
|
|
|
754
754
|
assert.equal(seen.length, LIVE_TOTALS.social + LIVE_TOTALS.transactional);
|
|
755
755
|
});
|
|
756
756
|
|
|
757
|
-
// No `limit`: countByMailbox still clamps its answer to the clamped limit,
|
|
758
|
-
// which is what #305 changes. What this asserts is the predicate — the
|
|
759
|
-
// count is over the mailbox rather than over a page of it.
|
|
760
757
|
test("countByMailbox counts the matches in the mailbox, not the page", async () => {
|
|
761
758
|
assert.equal(
|
|
762
759
|
await repo.countByMailbox(
|
|
@@ -769,6 +766,34 @@ describe("DrizzleThreadMessageRepository (sqlite)", () => {
|
|
|
769
766
|
);
|
|
770
767
|
});
|
|
771
768
|
|
|
769
|
+
// Regression for #509. The count was computed in full and then discarded
|
|
770
|
+
// down to THREAD_SEARCH_MAX_LIMIT, so this mailbox's 4,753 personal
|
|
771
|
+
// messages reported as 500 — a number that reads to the user as the whole
|
|
772
|
+
// match. A page size bounds the rows a response carries; it cannot bound
|
|
773
|
+
// how many messages match.
|
|
774
|
+
test("a match far larger than a page reports its real size", async () => {
|
|
775
|
+
assert.ok(
|
|
776
|
+
LIVE_TOTALS.personal > THREAD_SEARCH_MAX_LIMIT,
|
|
777
|
+
"the fixture has to outgrow the page cap for this to mean anything",
|
|
778
|
+
);
|
|
779
|
+
const page = await repo.searchByMailboxWindow(
|
|
780
|
+
CAT_ACCOUNT,
|
|
781
|
+
CAT_MAILBOX,
|
|
782
|
+
{ category: ["personal"] },
|
|
783
|
+
{ order: "desc", excludeDeleted: true },
|
|
784
|
+
);
|
|
785
|
+
assert.equal(page.items.length, THREAD_SEARCH_MAX_LIMIT);
|
|
786
|
+
assert.equal(
|
|
787
|
+
await repo.countByMailbox(
|
|
788
|
+
CAT_ACCOUNT,
|
|
789
|
+
CAT_MAILBOX,
|
|
790
|
+
{ category: ["personal"] },
|
|
791
|
+
{ excludeDeleted: true },
|
|
792
|
+
),
|
|
793
|
+
LIVE_TOTALS.personal,
|
|
794
|
+
);
|
|
795
|
+
});
|
|
796
|
+
|
|
772
797
|
test("the category predicate composes with the other filters", async () => {
|
|
773
798
|
const page = await repo.searchByMailboxWindow(
|
|
774
799
|
CAT_ACCOUNT,
|
|
@@ -241,15 +241,15 @@ describe("DrizzleThreadMessageRepository.searchByMailboxWindow / countByMailbox"
|
|
|
241
241
|
acct,
|
|
242
242
|
mbx,
|
|
243
243
|
{ subject: "match" },
|
|
244
|
-
{ excludeDeleted: true
|
|
244
|
+
{ excludeDeleted: true },
|
|
245
245
|
);
|
|
246
|
-
assert.equal(count,
|
|
246
|
+
assert.equal(count, 4, "count names every match, not one page of them");
|
|
247
247
|
});
|
|
248
248
|
|
|
249
249
|
// ── Scenario 5 ────────────────────────────────────────────────────────────
|
|
250
|
-
// desc default: the first page holds the newest matches; count
|
|
251
|
-
//
|
|
252
|
-
test("desc page holds the newest matches and count
|
|
250
|
+
// desc default: the first page holds the newest matches; the count names the
|
|
251
|
+
// whole match set behind that page.
|
|
252
|
+
test("desc page holds the newest matches and the count names the whole match", async () => {
|
|
253
253
|
const acct = uuid();
|
|
254
254
|
const mbx = uuid();
|
|
255
255
|
const now = Date.now();
|
|
@@ -277,14 +277,13 @@ describe("DrizzleThreadMessageRepository.searchByMailboxWindow / countByMailbox"
|
|
|
277
277
|
acct,
|
|
278
278
|
mbx,
|
|
279
279
|
{ subject: "alpha" },
|
|
280
|
-
{ excludeDeleted: true
|
|
280
|
+
{ excludeDeleted: true },
|
|
281
281
|
);
|
|
282
|
-
assert.equal(count,
|
|
283
|
-
assert.equal(count, 2);
|
|
282
|
+
assert.equal(count, 5, "every alpha row is counted, not the page of two");
|
|
284
283
|
});
|
|
285
284
|
|
|
286
285
|
// ── Scenario 6 ────────────────────────────────────────────────────────────
|
|
287
|
-
// order:asc returns the OLDEST matches first; count
|
|
286
|
+
// order:asc returns the OLDEST matches first; the count is order-independent.
|
|
288
287
|
test("order:asc returns the oldest matches first", async () => {
|
|
289
288
|
const acct = uuid();
|
|
290
289
|
const mbx = uuid();
|
|
@@ -317,10 +316,9 @@ describe("DrizzleThreadMessageRepository.searchByMailboxWindow / countByMailbox"
|
|
|
317
316
|
acct,
|
|
318
317
|
mbx,
|
|
319
318
|
{ subject: "beta" },
|
|
320
|
-
{ excludeDeleted: true,
|
|
319
|
+
{ excludeDeleted: true, order: "asc" },
|
|
321
320
|
);
|
|
322
|
-
assert.equal(count,
|
|
323
|
-
assert.equal(count, 2);
|
|
321
|
+
assert.equal(count, 5, "asc counts the whole match set too");
|
|
324
322
|
});
|
|
325
323
|
});
|
|
326
324
|
|
|
@@ -876,21 +876,19 @@ export class DrizzleThreadMessageRepository
|
|
|
876
876
|
}
|
|
877
877
|
|
|
878
878
|
/**
|
|
879
|
-
* COUNT of matches over the SAME predicate as `searchByMailboxWindow`,
|
|
880
|
-
*
|
|
881
|
-
*
|
|
879
|
+
* COUNT of matches over the SAME predicate as `searchByMailboxWindow`, over
|
|
880
|
+
* the whole mailbox. `THREAD_SEARCH_MAX_LIMIT` bounds a page of rows; a count
|
|
881
|
+
* returns no rows, so it is answered in full however many messages match.
|
|
882
882
|
*/
|
|
883
883
|
async countByMailbox(
|
|
884
884
|
accountConfigId: string,
|
|
885
885
|
mailboxId: string,
|
|
886
886
|
search: SearchOptions,
|
|
887
887
|
options?: {
|
|
888
|
-
limit?: number;
|
|
889
888
|
excludeDeleted?: boolean;
|
|
890
889
|
order?: "asc" | "desc";
|
|
891
890
|
},
|
|
892
891
|
): Promise<number> {
|
|
893
|
-
const cap = clampThreadSearchLimit(options?.limit);
|
|
894
892
|
const [{ count }] = await this.db
|
|
895
893
|
.select({ count: sql<number>`cast(count(*) as int)` })
|
|
896
894
|
.from(threadMessageTable)
|
|
@@ -904,7 +902,7 @@ export class DrizzleThreadMessageRepository
|
|
|
904
902
|
...buildSearchConditions(search),
|
|
905
903
|
),
|
|
906
904
|
);
|
|
907
|
-
return
|
|
905
|
+
return count;
|
|
908
906
|
}
|
|
909
907
|
|
|
910
908
|
async listAllByAccount(
|