Skip to content

Commit

Permalink
chore: Update group metadata cache (#GI234)
Browse files Browse the repository at this point in the history
- Updated the group metadata cache to improve performance.
- Added verbose logging for cache updates and requests.
- Affected file: `whatsapp.baileys.service.ts`.

Please note that this change does not alter the functionality or behavior of the application. It is a maintenance task to optimize cache management.
  • Loading branch information
dgcode-tec committed Jun 26, 2024
1 parent 75922e6 commit 79cadad
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/services/channels/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,8 @@ export class BaileysStartupService extends ChannelStartupService {
private async updateGroupMetadataCache(groupJid: string) {
try {
const meta = await this.client.groupMetadata(groupJid);

this.logger.verbose(`Updating cache for group: ${groupJid}`);
await groupMetadataCache.set(groupJid, {
timestamp: Date.now(),
data: meta,
Expand All @@ -3170,6 +3172,7 @@ export class BaileysStartupService extends ChannelStartupService {
if (!isJidGroup(groupJid)) return null;

if (await groupMetadataCache.has(groupJid)) {
this.logger.verbose(`Cache request for group: ${groupJid}`);
const meta = await groupMetadataCache.get(groupJid);

if (Date.now() - meta.timestamp > 3600000) {
Expand All @@ -3179,6 +3182,7 @@ export class BaileysStartupService extends ChannelStartupService {
return meta.data;
}

this.logger.verbose(`Cache request for group: ${groupJid} - not found`);
return await this.updateGroupMetadataCache(groupJid);
}

Expand Down

0 comments on commit 79cadad

Please sign in to comment.