Skip to content

Commit

Permalink
Revert the code changes using global objects as cache data
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Nov 1, 2023
1 parent ba80181 commit 0de0c5c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
10 changes: 2 additions & 8 deletions functions/internals/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export function deserializeTimeEntry(
}
}

let _fetchTimeEntry: SavedAttributes<TE> | undefined;
interface fetchTimeEntryArgs {
te: DataMapper<TE>;
user: string;
Expand All @@ -123,11 +122,9 @@ interface fetchTimeEntryArgs {
export async function fetchTimeEntry(
{ te, user, offset, yyyymmdd }: fetchTimeEntryArgs,
): Promise<SavedAttributes<TE>> {
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 {
Expand Down Expand Up @@ -177,7 +174,6 @@ export async function fetchAllMemberMonthTimeEntries(
return result;
}

let _fetchRecentTimeEntries: SavedAttributes<TE>[] | undefined;
interface fetchRecentTimeEntriesArgs {
te: DataMapper<TE>;
user: string;
Expand All @@ -190,7 +186,6 @@ export async function fetchRecentTimeEntries({
yyyymm,
limit,
}: fetchRecentTimeEntriesArgs): Promise<SavedAttributes<TE>[]> {
if (_fetchRecentTimeEntries) return _fetchRecentTimeEntries;
const monthsToSearch: string[] = [yyyymm];
let year = yyyymm.substring(0, 4);
let month = yyyymm.substring(4, 6);
Expand All @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions functions/internals/slack_api.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { SlackAPIClient, UsersInfoResponse } from "slack-web-api-client/mod.ts";

let _fetchUserDetails: UsersInfoResponse | undefined;
interface fetchUserDetailsArgs {
slackApi: SlackAPIClient;
user: string;
}
export async function fetchUserDetails(
{ slackApi, user }: fetchUserDetailsArgs,
): Promise<UsersInfoResponse> {
if (_fetchUserDetails) return _fetchUserDetails;
_fetchUserDetails = await slackApi.users.info({
return await slackApi.users.info({
user,
include_locale: true,
});
return _fetchUserDetails;
}

0 comments on commit 0de0c5c

Please sign in to comment.