feat: Re-enable group metadata caching in Baileys service

- Restore group metadata caching mechanisms
- Uncomment cache-related methods for group updates and participants
- Implement conditional group metadata retrieval based on cache configuration
This commit is contained in:
Davidson Gomes 2025-02-02 16:42:17 -03:00
parent 4a5d7a91e2
commit 3c2ea5c67c

View File

@ -668,7 +668,7 @@ export class BaileysStartupService extends ChannelStartupService {
shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => {
return this.historySyncNotification(msg);
},
// cachedGroupMetadata: this.getGroupMetadataCache,
cachedGroupMetadata: this.getGroupMetadataCache,
userDevicesCache: this.userDevicesCache,
transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
patchMessageBeforeSending(message) {
@ -1562,11 +1562,11 @@ export class BaileysStartupService extends ChannelStartupService {
'groups.update': (groupMetadataUpdate: Partial<GroupMetadata>[]) => {
this.sendDataWebhook(Events.GROUPS_UPDATE, groupMetadataUpdate);
// groupMetadataUpdate.forEach((group) => {
// if (isJidGroup(group.id)) {
// this.updateGroupMetadataCache(group.id);
// }
// });
groupMetadataUpdate.forEach((group) => {
if (isJidGroup(group.id)) {
this.updateGroupMetadataCache(group.id);
}
});
},
'group-participants.update': (participantsUpdate: {
@ -1576,7 +1576,7 @@ export class BaileysStartupService extends ChannelStartupService {
}) => {
this.sendDataWebhook(Events.GROUP_PARTICIPANTS_UPDATE, participantsUpdate);
// this.updateGroupMetadataCache(participantsUpdate.id);
this.updateGroupMetadataCache(participantsUpdate.id);
},
};
@ -2160,10 +2160,10 @@ export class BaileysStartupService extends ChannelStartupService {
if (isJidGroup(sender)) {
let group;
try {
// const cache = this.configService.get<CacheConf>('CACHE');
// if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner');
// else group = await this.getGroupMetadataCache(sender);
group = await this.findGroup({ groupJid: sender }, 'inner');
const cache = this.configService.get<CacheConf>('CACHE');
if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner');
else group = await this.getGroupMetadataCache(sender);
// group = await this.findGroup({ groupJid: sender }, 'inner');
} catch (error) {
throw new NotFoundException('Group not found');
}