From 0de0c5c65ebb892d39400b3bee805eec1a368bf3 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Wed, 1 Nov 2023 12:16:59 +0900 Subject: [PATCH] Revert the code changes using global objects as cache data --- functions/internals/datastore.ts | 10 ++-------- functions/internals/slack_api.ts | 5 +---- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/functions/internals/datastore.ts b/functions/internals/datastore.ts index 342c93d..a1d10d2 100644 --- a/functions/internals/datastore.ts +++ b/functions/internals/datastore.ts @@ -113,7 +113,6 @@ export function deserializeTimeEntry( } } -let _fetchTimeEntry: SavedAttributes | undefined; interface fetchTimeEntryArgs { te: DataMapper; user: string; @@ -123,11 +122,9 @@ interface fetchTimeEntryArgs { export async function fetchTimeEntry( { te, user, offset, yyyymmdd }: fetchTimeEntryArgs, ): Promise> { - if (_fetchTimeEntry) return _fetchTimeEntry; const _yyyymmdd = yyyymmdd ?? todayYYYYMMDD(offset); const response = await te.findById(`${user}-${_yyyymmdd}`); - _fetchTimeEntry = response.item; - return _fetchTimeEntry; + return response.item; } interface fetchMonthTimeEntriesArgs { @@ -177,7 +174,6 @@ export async function fetchAllMemberMonthTimeEntries( return result; } -let _fetchRecentTimeEntries: SavedAttributes[] | undefined; interface fetchRecentTimeEntriesArgs { te: DataMapper; user: string; @@ -190,7 +186,6 @@ export async function fetchRecentTimeEntries({ yyyymm, limit, }: fetchRecentTimeEntriesArgs): Promise[]> { - if (_fetchRecentTimeEntries) return _fetchRecentTimeEntries; const monthsToSearch: string[] = [yyyymm]; let year = yyyymm.substring(0, 4); let month = yyyymm.substring(4, 6); @@ -215,8 +210,7 @@ export async function fetchRecentTimeEntries({ if (!a.user_and_date || !b.user_and_date) return 0; return a.user_and_date > b.user_and_date ? 1 : -1; }); - _fetchRecentTimeEntries = items; - return _fetchRecentTimeEntries; + return items; } interface saveTimeEntryArgs { diff --git a/functions/internals/slack_api.ts b/functions/internals/slack_api.ts index c786450..dd42716 100644 --- a/functions/internals/slack_api.ts +++ b/functions/internals/slack_api.ts @@ -1,6 +1,5 @@ import { SlackAPIClient, UsersInfoResponse } from "slack-web-api-client/mod.ts"; -let _fetchUserDetails: UsersInfoResponse | undefined; interface fetchUserDetailsArgs { slackApi: SlackAPIClient; user: string; @@ -8,10 +7,8 @@ interface fetchUserDetailsArgs { export async function fetchUserDetails( { slackApi, user }: fetchUserDetailsArgs, ): Promise { - if (_fetchUserDetails) return _fetchUserDetails; - _fetchUserDetails = await slackApi.users.info({ + return await slackApi.users.info({ user, include_locale: true, }); - return _fetchUserDetails; }