@remit/drizzle-service 1.0.0 → 1.0.1
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 +1 -1
- package/src/repos/message.ts +28 -23
package/package.json
CHANGED
package/src/repos/message.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
lt,
|
|
19
19
|
or,
|
|
20
20
|
type SQL,
|
|
21
|
+
sql,
|
|
21
22
|
} from "drizzle-orm";
|
|
22
23
|
import type { SqliteBatchItem, WriteBatch } from "../batch.js";
|
|
23
24
|
import { chunk, chunkRows } from "../bound-parameters.js";
|
|
@@ -280,6 +281,32 @@ const placementTerms = (expected: PlacementPredicate): SQL[] => {
|
|
|
280
281
|
return terms;
|
|
281
282
|
};
|
|
282
283
|
|
|
284
|
+
/** The rows `listStrandedPlacements` returns: `moving` or `deleting`, unwritten since `untouchedSince`. */
|
|
285
|
+
export const strandedPlacementCondition = (
|
|
286
|
+
mailboxIds: readonly string[],
|
|
287
|
+
untouchedSince: number,
|
|
288
|
+
): SQL =>
|
|
289
|
+
and(
|
|
290
|
+
lt(messageTable.updatedAt, untouchedSince),
|
|
291
|
+
or(
|
|
292
|
+
and(
|
|
293
|
+
eq(messageTable.status, "moving"),
|
|
294
|
+
inList(messageTable.originalMailboxId, mailboxIds),
|
|
295
|
+
isNotNull(messageTable.originalUid),
|
|
296
|
+
),
|
|
297
|
+
and(
|
|
298
|
+
eq(messageTable.status, "deleting"),
|
|
299
|
+
inList(messageTable.mailboxId, mailboxIds),
|
|
300
|
+
),
|
|
301
|
+
and(
|
|
302
|
+
eq(messageTable.status, "moving"),
|
|
303
|
+
eq(messageTable.uid, 0),
|
|
304
|
+
isNull(messageTable.originalUid),
|
|
305
|
+
inList(messageTable.mailboxId, mailboxIds),
|
|
306
|
+
),
|
|
307
|
+
),
|
|
308
|
+
) ?? sql`0`;
|
|
309
|
+
|
|
283
310
|
export class DrizzleMessageRepository implements IMessageRepository {
|
|
284
311
|
private readonly db: DB;
|
|
285
312
|
private readonly batch: WriteBatch;
|
|
@@ -888,32 +915,10 @@ export class DrizzleMessageRepository implements IMessageRepository {
|
|
|
888
915
|
untouchedSince: number,
|
|
889
916
|
): ReturnType<IMessageRepository["listStrandedPlacements"]> {
|
|
890
917
|
if (mailboxIds.length === 0) return [];
|
|
891
|
-
const ids = [...mailboxIds];
|
|
892
918
|
const rows = await this.db
|
|
893
919
|
.select()
|
|
894
920
|
.from(messageTable)
|
|
895
|
-
.where(
|
|
896
|
-
and(
|
|
897
|
-
lt(messageTable.updatedAt, untouchedSince),
|
|
898
|
-
or(
|
|
899
|
-
and(
|
|
900
|
-
eq(messageTable.status, "moving"),
|
|
901
|
-
inList(messageTable.originalMailboxId, ids),
|
|
902
|
-
isNotNull(messageTable.originalUid),
|
|
903
|
-
),
|
|
904
|
-
and(
|
|
905
|
-
eq(messageTable.status, "deleting"),
|
|
906
|
-
inList(messageTable.mailboxId, ids),
|
|
907
|
-
),
|
|
908
|
-
and(
|
|
909
|
-
eq(messageTable.status, "moving"),
|
|
910
|
-
eq(messageTable.uid, 0),
|
|
911
|
-
isNull(messageTable.originalUid),
|
|
912
|
-
inList(messageTable.mailboxId, ids),
|
|
913
|
-
),
|
|
914
|
-
),
|
|
915
|
-
),
|
|
916
|
-
)
|
|
921
|
+
.where(strandedPlacementCondition(mailboxIds, untouchedSince))
|
|
917
922
|
.orderBy(asc(messageTable.updatedAt), asc(messageTable.messageId));
|
|
918
923
|
return rows.map(toMessageItem);
|
|
919
924
|
}
|