Skip to content

Commit 0fbdacd

Browse files
committed
refactor: 불필요 쿼리 및 페이지네이션 제거
1 parent b366cdd commit 0fbdacd

1 file changed

Lines changed: 3 additions & 14 deletions

File tree

Firebase/functions/src/todo/cleanup.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,12 @@ export const cleanupSoftDeletedTodos = onSchedule({
8181
},
8282
async () => {
8383
try {
84-
let lastDocument:
85-
FirebaseFirestore.QueryDocumentSnapshot<FirebaseFirestore.DocumentData> | undefined;
86-
8784
while (true) {
88-
let query = admin.firestore()
85+
const snapshot = await admin.firestore()
8986
.collectionGroup("todoLists")
9087
.where("isDeleted", "==", true)
91-
.orderBy(admin.firestore.FieldPath.documentId())
92-
.limit(QUERY_BATCH_SIZE);
93-
94-
if (lastDocument) {
95-
query = query.startAfter(lastDocument);
96-
}
97-
98-
const snapshot = await query.get();
88+
.limit(QUERY_BATCH_SIZE)
89+
.get();
9990
if (snapshot.empty) { return; }
10091

10192
const batch = admin.firestore().batch();
@@ -105,7 +96,6 @@ export const cleanupSoftDeletedTodos = onSchedule({
10596
await batch.commit();
10697

10798
if (snapshot.size < QUERY_BATCH_SIZE) { return; }
108-
lastDocument = snapshot.docs[snapshot.docs.length - 1];
10999
}
110100
} catch (error) {
111101
logger.error(
@@ -114,7 +104,6 @@ export const cleanupSoftDeletedTodos = onSchedule({
114104
{
115105
collectionGroup: "todoLists",
116106
filter: "isDeleted == true",
117-
orderBy: "__name__",
118107
queryBatchSize: QUERY_BATCH_SIZE
119108
}
120109
);

0 commit comments

Comments
 (0)