server: misc services code cleanup #275
Loading…
Reference in a new issue
No description provided.
Delete branch "refactor/services"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
2d97af5acc
to5a442bb7bb
server: misc code cleanupto server: misc services code cleanup@ -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,
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.The cache in
services/relay.ts
usesnull
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.)Kinda confused with the
localUserByNativeTokenCache
. It uses the user'stoken
as a key. But according to the comment for thetoken
field:Not sure what's the best approach for this.
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:
@ -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>;
Does the type definition also have to say
async
?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.@ -35,3 +36,3 @@
}
if (Users.isLocalUser(user)) {
localUserByNativeTokenCache.set(user.token, user);
localUserByNativeTokenCache.set(user.token ?? '', user);
If a user is local, then
user.token
must have a value.3c13e20a29
to3cf673960b