Skip to content

Commit 7af75f3

Browse files
committed
refactor: compactedAt에 대한 쿼리를 제거하고 해당 필드의 존재 유무로 압축 여부를 결정하도록 개선
1 parent 0068cde commit 7af75f3

2 files changed

Lines changed: 4 additions & 42 deletions

File tree

Firebase/firestore.index.json

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
{
22
"indexes": [
3-
{
4-
"collectionGroup": "todoLists",
5-
"queryScope": "COLLECTION_GROUP",
6-
"fields": [
7-
{
8-
"fieldPath": "compactedAt",
9-
"order": "ASCENDING"
10-
},
11-
{
12-
"fieldPath": "deletedAt",
13-
"order": "ASCENDING"
14-
},
15-
{
16-
"fieldPath": "__name__",
17-
"order": "ASCENDING"
18-
}
19-
]
20-
},
213
{
224
"collectionGroup": "todoLists",
235
"queryScope": "COLLECTION_GROUP",
@@ -606,28 +588,6 @@
606588
}
607589
],
608590
"fieldOverrides": [
609-
{
610-
"collectionGroup": "todoLists",
611-
"fieldPath": "compactedAt",
612-
"indexes": [
613-
{
614-
"order": "ASCENDING",
615-
"queryScope": "COLLECTION"
616-
},
617-
{
618-
"order": "DESCENDING",
619-
"queryScope": "COLLECTION"
620-
},
621-
{
622-
"order": "ASCENDING",
623-
"queryScope": "COLLECTION_GROUP"
624-
},
625-
{
626-
"order": "DESCENDING",
627-
"queryScope": "COLLECTION_GROUP"
628-
}
629-
]
630-
},
631591
{
632592
"collectionGroup": "todoLists",
633593
"fieldPath": "createdAt",

Firebase/functions/src/todo/cleanup.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export const compactSoftDeletedTodos = onSchedule({
2424
while (true) {
2525
let query = admin.firestore()
2626
.collectionGroup("todoLists")
27-
.where("compactedAt", "==", null)
2827
.where("deletedAt", "<=", admin.firestore.Timestamp.fromDate(cutoff))
2928
.orderBy("deletedAt")
3029
.orderBy(admin.firestore.FieldPath.documentId())
@@ -38,6 +37,9 @@ export const compactSoftDeletedTodos = onSchedule({
3837

3938
const batch = admin.firestore().batch();
4039
snapshot.docs.forEach((document) => {
40+
if (document.data()?.compactedAt) {
41+
return;
42+
}
4143
batch.update(document.ref, {
4244
compactedAt: admin.firestore.FieldValue.serverTimestamp(),
4345
content: admin.firestore.FieldValue.delete(),
@@ -61,7 +63,7 @@ export const compactSoftDeletedTodos = onSchedule({
6163
toError(error),
6264
{
6365
collectionGroup: "todoLists",
64-
filter: `compactedAt == null && deletedAt <= now - ${TOMBSTONE_GRACE_PERIOD_HOURS}h`,
66+
filter: `deletedAt <= now - ${TOMBSTONE_GRACE_PERIOD_HOURS}h`,
6567
orderBy: ["deletedAt", "documentId"],
6668
cleanupBatchSize: CLEANUP_BATCH_SIZE
6769
}

0 commit comments

Comments
 (0)