Skip to content
Merged
95 changes: 94 additions & 1 deletion Firebase/firestore.index.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
"fieldPath": "dueDate",
"order": "ASCENDING"
},
{
"fieldPath": "__name__",
"order": "ASCENDING"
}
]
},
Expand Down Expand Up @@ -573,5 +577,94 @@
]
}
],
"fieldOverrides": []
"fieldOverrides": [
{
"collectionGroup": "todoLists",
"fieldPath": "dueDate",
"indexes": [
{
"order": "ASCENDING",
"queryScope": "COLLECTION"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION"
},
{
"order": "ASCENDING",
"queryScope": "COLLECTION_GROUP"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION_GROUP"
}
]
},
{
"collectionGroup": "todoLists",
"fieldPath": "isDeleted",
"indexes": [
{
"order": "ASCENDING",
"queryScope": "COLLECTION"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION"
},
{
"order": "ASCENDING",
"queryScope": "COLLECTION_GROUP"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION_GROUP"
}
]
},
{
"collectionGroup": "notifications",
"fieldPath": "isDeleted",
"indexes": [
{
"order": "ASCENDING",
"queryScope": "COLLECTION"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION"
},
{
"order": "ASCENDING",
"queryScope": "COLLECTION_GROUP"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION_GROUP"
}
]
},
{
"collectionGroup": "webPages",
"fieldPath": "isDeleted",
"indexes": [
{
"order": "ASCENDING",
"queryScope": "COLLECTION"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION"
},
{
"order": "ASCENDING",
"queryScope": "COLLECTION_GROUP"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION_GROUP"
}
]
}
]
}
16 changes: 3 additions & 13 deletions Firebase/functions/src/common/error.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
export function normalizeError(error: unknown): Record<string, unknown> {
const normalized = error as {
code?: unknown;
details?: unknown;
message?: unknown;
stack?: unknown;
};
return {
code: normalized?.code ?? null,
details: normalized?.details ?? null,
message: normalized?.message ?? String(error),
stack: normalized?.stack ?? null
};
export function toError(error: unknown): Error {
if (error instanceof Error) { return error; }
return new Error(String(error));
}
7 changes: 3 additions & 4 deletions Firebase/functions/src/fcm/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { onTaskDispatched } from "firebase-functions/v2/tasks";
import * as admin from "firebase-admin";
import * as logger from "firebase-functions/logger";
import { formatDateKey, toDate } from "../common/date";
import { normalizeError } from "../common/error";
import { toError } from "../common/error";
import { FirestorePath } from "../common/firestorePath";
import { resolveTimeZone } from "./shared";

Expand Down Expand Up @@ -131,9 +131,8 @@ export const sendPushNotification = onTaskDispatched({
}

} catch (error) {
logger.error("알림 발송 중 오류 발생", {
payload: req.data,
error: normalizeError(error)
logger.error("알림 발송 중 오류 발생", toError(error), {
payload: req.data
});
}
}
Expand Down
24 changes: 10 additions & 14 deletions Firebase/functions/src/fcm/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getFunctions } from "firebase-admin/functions";
import * as admin from "firebase-admin";
import * as logger from "firebase-functions/logger";
import { addDays, getZonedParts, zonedDateTimeToUTC } from "../common/date";
import { normalizeError } from "../common/error";
import { toError } from "../common/error";
import { FirestorePath } from "../common/firestorePath";
import { resolveTimeZone } from "./shared";

Expand All @@ -27,9 +27,8 @@ export const scheduleTodoReminder = onSchedule({
try {
usersSnapshot = await admin.firestore().collection("users").get();
} catch (error) {
logger.error("users 조회 실패", {
at: "collection(users).get()",
...normalizeError(error)
logger.error("users 조회 실패", toError(error), {
at: "collection(users).get()"
});
return;
}
Expand All @@ -42,10 +41,9 @@ export const scheduleTodoReminder = onSchedule({
.doc(FirestorePath.userData(userId, FirestorePath.UserDataDocument.settings))
.get();
} catch (error) {
logger.error("settings 조회 실패", {
logger.error("settings 조회 실패", toError(error), {
userId,
at: "users/{uid}/userData/settings",
...normalizeError(error)
at: "users/{uid}/userData/settings"
});
continue;
}
Expand Down Expand Up @@ -93,13 +91,12 @@ export const scheduleTodoReminder = onSchedule({
.where("dueDate", "<", admin.firestore.Timestamp.fromDate(endUTC))
.get();
} catch (error) {
logger.error("todoLists 조회 실패", {
logger.error("todoLists 조회 실패", toError(error), {
userId,
at: "todoLists.where(dueDate>=start).where(dueDate<end)",
startUTC: startUTC.toISOString(),
endUTC: endUTC.toISOString(),
dueDateKey,
...normalizeError(error)
dueDateKey
});
continue;
}
Expand All @@ -121,18 +118,17 @@ export const scheduleTodoReminder = onSchedule({
try {
await queue.enqueue(notificationPayload);
} catch (error) {
logger.error("Cloud Tasks enqueue 실패", {
logger.error("Cloud Tasks enqueue 실패", toError(error), {
userId,
todoId: todoDoc.id,
dueDateKey,
...normalizeError(error)
dueDateKey
});
}
}
}

} catch (error) {
logger.error("알림 스케줄 배치 실행 중 오류 발생", normalizeError(error));
logger.error("알림 스케줄 배치 실행 중 오류 발생", toError(error));
}
}
);
10 changes: 5 additions & 5 deletions Firebase/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ import {
} from "./fcm/schedule";

import {
removeTodoNotificationDocuments,
removeCompletedTodoNotificationRecords,
cleanupSoftDeletedTodos,
cleanupUnusedTodoNotificationRecords
cleanupSoftDeletedTodos
} from "./todo/cleanup";

import {
Expand All @@ -61,6 +58,9 @@ import {
} from "./notification/deletion";

import {
removeTodoNotificationDocuments,
removeCompletedTodoNotificationRecords,
cleanupNotificationDispatches,
cleanupSoftDeletedNotifications
} from "./notification/cleanup";

Expand Down Expand Up @@ -114,7 +114,7 @@ export {
removeTodoNotificationDocuments,
removeCompletedTodoNotificationRecords,
cleanupSoftDeletedTodos,
cleanupUnusedTodoNotificationRecords,
cleanupNotificationDispatches,
syncTodoNotificationCategory,
requestMoveRemovedCategoryTodosToEtc,
completeMoveRemovedCategoryTodosToEtc,
Expand Down
Loading