fix metrics cardinality and stream key cache counts

This commit is contained in:
2026-03-12 20:16:01 +01:00
parent cdb0c01ffd
commit fcdbc4e878
2 changed files with 11 additions and 3 deletions

View File

@@ -768,7 +768,12 @@ app.get(
chatUser.isBot ? 'bot' : 'user',
Buffer.byteLength(message)
);
recordUniqueChatter(chatUser.isBot ? 'bot' : 'user');
const isFirstMessageFromUser =
(await redis.sadd(`chat:unique-chatters:${targetUsername}`, chatUser.id)) === 1;
if (isFirstMessageFromUser) {
recordUniqueChatter(chatUser.isBot ? 'bot' : 'user');
}
outcome = 'broadcast';
}
if (msg.type === 'emojiMsg') {

View File

@@ -12,6 +12,7 @@ export default async function syncStreamKeys() {
});
if (keys.length === 0) {
setCacheEntryCount('stream_keys', 0);
console.log('No stream keys found to sync.');
return;
}
@@ -19,15 +20,17 @@ export default async function syncStreamKeys() {
const redis = getRedisConnection();
const pipeline = redis.pipeline();
let syncedKeyCount = 0;
for (const key of keys) {
if (key.channel && key.channel.name) {
pipeline.set(`streamKey:${key.channel.name}`, key.key);
syncedKeyCount += 1;
}
}
await pipeline.exec();
setCacheEntryCount('stream_keys', keys.length);
console.log(`Synced ${keys.length} stream keys to Redis`);
setCacheEntryCount('stream_keys', syncedKeyCount);
console.log(`Synced ${syncedKeyCount} stream keys to Redis`);
});
} catch (error) {
console.error('Failed to sync stream keys to Redis:', error);