Skip to content

Commit bedee53

Browse files
authored
bug: fix last signed in at cache (#184)
1 parent da93fc2 commit bedee53

3 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/auth/auth.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class AuthController {
7373
__typename: true,
7474
},
7575
});
76-
await this.cache.put(lastSignInKey, true, 60 * 60 * 1000);
76+
await this.cache.put(lastSignInKey, true, 60 * 60);
7777
user.last_sign_in_at = now;
7878
}
7979

src/hasura/hasura.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class HasuraService {
4141
}
4242

4343
public static PLAYER_LAST_SIGN_IN_CACHE_KEY(steamId: bigint | string) {
44-
return `user:last_sign_in_at:${steamId.toString()}`;
44+
return `user:last_sign_in_at:v2:${steamId.toString()}`;
4545
}
4646

4747
public checkSecret(secret: string) {

src/type-sense/type-sense.service.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ export class TypeSenseService {
9494
type: "string",
9595
symbols_to_index: ["~"],
9696
optional: true,
97+
sort: true,
98+
index: true,
9799
},
98100
];
99101

@@ -112,18 +114,37 @@ export class TypeSenseService {
112114

113115
const collection = await this.client.collections("players").retrieve();
114116

115-
const missingFields = fields.filter((field) => {
116-
return !collection.fields.find((_existingField) => {
117-
return _existingField.name === field.name;
118-
});
119-
});
117+
const fieldUpdates: Array<Record<string, unknown>> = [];
118+
let needsRefresh = false;
119+
120+
for (const field of fields) {
121+
const existing = collection.fields.find((f) => f.name === field.name);
122+
123+
if (!existing) {
124+
fieldUpdates.push(field);
125+
needsRefresh = true;
126+
continue;
127+
}
120128

121-
if (missingFields.length > 0) {
129+
const sortChanged = Boolean(existing.sort) !== Boolean(field.sort);
130+
const indexChanged = Boolean(existing.index) !== Boolean(field.index);
131+
const typeChanged = existing.type !== field.type;
132+
133+
if (sortChanged || indexChanged || typeChanged) {
134+
fieldUpdates.push({ name: field.name, drop: true });
135+
fieldUpdates.push(field);
136+
needsRefresh = true;
137+
}
138+
}
139+
140+
if (fieldUpdates.length > 0) {
122141
await this.client.collections("players").update({
123-
fields: missingFields,
142+
fields: fieldUpdates as CollectionFieldSchema[],
124143
});
125144

126-
await this.queue.add(RefreshAllPlayersJob.name, {});
145+
if (needsRefresh) {
146+
await this.queue.add(RefreshAllPlayersJob.name, {});
147+
}
127148
}
128149
}
129150

0 commit comments

Comments
 (0)