server: misc services code cleanup #275

Merged
norm merged 7 commits from refactor/services into main 2022-12-10 04:10:44 +00:00
Owner
No description provided.
norm force-pushed refactor/services from 2d97af5acc to 5a442bb7bb 2022-12-07 20:04:26 +00:00 Compare
norm changed title from server: misc code cleanup to server: misc services code cleanup 2022-12-07 20:05:04 +00:00
Johann150 reviewed 2022-12-07 22:02:06 +00:00
@ -6,3 +7,3 @@
export const userByIdCache = new Cache<CacheableUser>(
Infinity,
(id) => Users.findOneBy({ id }).then(x => x ?? undefined),
async (id) => id ? (await Users.findOneBy({ id }) ?? undefined) : undefined,
Owner

I don't think checking whether id is undefined is necessary. Similar for the other caches here. It would not make sense for the cache key to be undefined.

I don't think checking whether `id` is undefined is necessary. Similar for the other caches here. It would not make sense for the cache key to be undefined.
norm marked this conversation as resolved
Owner

The cache in services/relay.ts uses null as the only cache key. I guess that one could use an empty string instead? (Also not sure if that's the only place that had a cache with only one key, please check.)

The cache in `services/relay.ts` uses `null` as the only cache key. I guess that one could use an empty string instead? (Also not sure if that's the only place that had a cache with only one key, please check.)
Author
Owner

Kinda confused with the localUserByNativeTokenCache. It uses the user's token as a key. But according to the comment for the token field:

The native access token of the User. It will be null if the origin of the user is local.

Not sure what's the best approach for this.

Kinda confused with the `localUserByNativeTokenCache`. It uses the user's `token` as a key. But according to the comment for the `token` field: > The native access token of the User. It will be null if the origin of the user is local. Not sure what's the best approach for this.
Owner

I'm pretty sure that comment is wrong, because that would make no sense. The native token is used by the "native" frontend. It would make no sense for remote users to have a token.

The comment should probably be:

The native access token of local users, or null.

I'm pretty sure that comment is wrong, because that would make no sense. The native token is used by the "native" frontend. It would make no sense for remote users to have a token. The comment should probably be: > The native access token of local users, or null.
Johann150 reviewed 2022-12-08 18:57:11 +00:00
@ -3,2 +2,3 @@
public cache: Map<string, { date: number; value: T; }>;
private lifetime: number;
public fetcher: (key: string | null) => Promise<T | undefined>;
public fetcher: (key: string) => Promise<T | undefined>;
Owner

Does the type definition also have to say async?

Does the type definition also have to say `async`?
Author
Owner

I don't think it's necessary since it's a function that returns a promise. async is syntactic sugar that wraps the function's return value in a promise.

I don't think it's necessary since it's a function that returns a promise. `async` is syntactic sugar that wraps the function's return value in a promise.
Johann150 marked this conversation as resolved
@ -35,3 +36,3 @@
}
if (Users.isLocalUser(user)) {
localUserByNativeTokenCache.set(user.token, user);
localUserByNativeTokenCache.set(user.token ?? '', user);
Owner

If a user is local, then user.token must have a value.

If a user is local, then `user.token` must have a value.
norm marked this conversation as resolved
norm force-pushed refactor/services from 3c13e20a29 to 3cf673960b 2022-12-09 04:21:48 +00:00 Compare
Johann150 approved these changes 2022-12-09 18:09:20 +00:00
norm merged commit f46ba3f700 into main 2022-12-10 04:10:44 +00:00
norm deleted branch refactor/services 2022-12-10 04:10:44 +00:00
Sign in to join this conversation.
No reviewers
No labels
feature
fix
upkeep
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: FoundKeyGang/FoundKey#275
No description provided.