Skip to content

Commit 9b0fa3b

Browse files
committed
added ETag support + removed duplicated token checks on dailyRatingsStats endpoint
1 parent ed082a7 commit 9b0fa3b

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

cloud/functions/src/functions/http/api/events-routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,6 @@ export function declareEventHttpRoutes(app: Express) {
124124
})
125125
}),
126126
ensureHasFamilyOrEventOrganizerToken(),
127-
async (res, path, query) =>
128-
(await import("../event/dailyRatingsStats")).provideDailyRatingsStats(res, path, query));
127+
async (res, path, query, eventDescriptor, req) =>
128+
(await import("../event/dailyRatingsStats")).provideDailyRatingsStats(res, path, query, req));
129129
}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
import {Response} from "express";
1+
import {Response, Request} from "express";
22
import {logPerf, sendResponseMessage} from "../utils";
3-
import {getEventDescriptor} from "../../firestore/services/eventDescriptor-utils";
4-
import {getFamilyOrganizerToken} from "../../firestore/services/publicTokens-utils";
5-
import {getSecretTokenRef} from "../../firestore/firestore-utils";
3+
import {checkEventLastUpdate, getSecretTokenRef} from "../../firestore/firestore-utils";
64
import {DailyTalkFeedbackRatings} from "../../../../../../shared/conference-organizer-space.firestore";
75
import {firestore} from "firebase-admin";
86
import {match} from "ts-pattern";
97
import DocumentReference = firestore.DocumentReference;
108

119

12-
export async function provideDailyRatingsStats(response: Response, pathParams: {eventId: string}, queryParams: {token: string}) {
10+
export async function provideDailyRatingsStats(response: Response, pathParams: {eventId: string}, queryParams: {token: string}, request: Request) {
1311

14-
const [eventDescriptor, familyOrganizerToken] = await logPerf("eventDescriptor and familyRoomStatsContributor retrieval", async () => {
15-
return await Promise.all([
16-
getEventDescriptor(pathParams.eventId),
17-
getFamilyOrganizerToken(queryParams.token),
18-
]);
19-
})
12+
const { cachedHash, updatesDetected } = await logPerf("cached hash", async () => {
13+
return await checkEventLastUpdate(pathParams.eventId, [
14+
root => root.allFeedbacks,
15+
root => root.talkListUpdated
16+
], request, response)
17+
});
2018

21-
if (!eventDescriptor.eventFamily || !familyOrganizerToken.eventFamilies.includes(eventDescriptor.eventFamily)) {
22-
return sendResponseMessage(response, 400, `Provided family organizer token doesn't match with event ${pathParams.eventId} family: [${eventDescriptor.eventFamily}]`)
19+
if(!updatesDetected) {
20+
return sendResponseMessage(response, 304)
2321
}
2422

2523
const organizerSpaceRef = await getSecretTokenRef(`events/${pathParams.eventId}/organizer-space`);
@@ -39,5 +37,7 @@ export async function provideDailyRatingsStats(response: Response, pathParams: {
3937

4038
sendResponseMessage(response, 200, {
4139
dailyFeedbacks
42-
});
40+
}, cachedHash ? {
41+
'ETag': cachedHash
42+
}:{});
4343
}

0 commit comments

Comments
 (0)