MSTeams: dedupe sent-message cache storage (#22514)
Merged via /review-pr -> /prepare-pr -> /merge-pr. Prepared head SHA: 88e14dcbe13006c4d1f353c0e7e196175747a4c8 Co-authored-by: TaKO8Ki <41065217+TaKO8Ki@users.noreply.github.com> Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com> Reviewed-by: @obviyus
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
const TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
||||
|
||||
type CacheEntry = {
|
||||
messageIds: Set<string>;
|
||||
timestamps: Map<string, number>;
|
||||
};
|
||||
|
||||
@@ -11,7 +10,6 @@ function cleanupExpired(entry: CacheEntry): void {
|
||||
const now = Date.now();
|
||||
for (const [msgId, timestamp] of entry.timestamps) {
|
||||
if (now - timestamp > TTL_MS) {
|
||||
entry.messageIds.delete(msgId);
|
||||
entry.timestamps.delete(msgId);
|
||||
}
|
||||
}
|
||||
@@ -23,12 +21,11 @@ export function recordMSTeamsSentMessage(conversationId: string, messageId: stri
|
||||
}
|
||||
let entry = sentMessages.get(conversationId);
|
||||
if (!entry) {
|
||||
entry = { messageIds: new Set(), timestamps: new Map() };
|
||||
entry = { timestamps: new Map() };
|
||||
sentMessages.set(conversationId, entry);
|
||||
}
|
||||
entry.messageIds.add(messageId);
|
||||
entry.timestamps.set(messageId, Date.now());
|
||||
if (entry.messageIds.size > 200) {
|
||||
if (entry.timestamps.size > 200) {
|
||||
cleanupExpired(entry);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +36,7 @@ export function wasMSTeamsMessageSent(conversationId: string, messageId: string)
|
||||
return false;
|
||||
}
|
||||
cleanupExpired(entry);
|
||||
return entry.messageIds.has(messageId);
|
||||
return entry.timestamps.has(messageId);
|
||||
}
|
||||
|
||||
export function clearMSTeamsSentMessageCache(): void {
|
||||
|
||||
Reference in New Issue
Block a user