mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
Removed redis cache from is on whatsapp
This commit is contained in:
parent
49806cf47e
commit
41342f39de
@ -180,9 +180,6 @@ CACHE_REDIS_PREFIX_KEY=evolution
|
||||
CACHE_REDIS_SAVE_INSTANCES=false
|
||||
# Local Cache enabled
|
||||
CACHE_LOCAL_ENABLED=false
|
||||
# Local Cache enabled
|
||||
CACHE_REDIS_SAVE_IS_ON_WHATSAPP=false
|
||||
CACHE_REDIS_SAVE_IS_ON_WHATSAPP_DAYS=7
|
||||
|
||||
# Amazon S3 - Environment variables
|
||||
S3_ENABLED=false
|
||||
|
@ -169,8 +169,6 @@ export type CacheConfRedis = {
|
||||
PREFIX_KEY: string;
|
||||
TTL: number;
|
||||
SAVE_INSTANCES: boolean;
|
||||
SAVE_IS_ON_WHATSAPP: boolean;
|
||||
SAVE_IS_ON_WHATSAPP_TTL: number;
|
||||
};
|
||||
export type CacheConfLocal = {
|
||||
ENABLED: boolean;
|
||||
@ -457,9 +455,6 @@ export class ConfigService {
|
||||
PREFIX_KEY: process.env?.CACHE_REDIS_PREFIX_KEY || 'evolution-cache',
|
||||
TTL: Number.parseInt(process.env?.CACHE_REDIS_TTL) || 604800,
|
||||
SAVE_INSTANCES: process.env?.CACHE_REDIS_SAVE_INSTANCES === 'true',
|
||||
SAVE_IS_ON_WHATSAPP: process.env?.CACHE_REDIS_SAVE_IS_ON_WHATSAPP === 'true',
|
||||
SAVE_IS_ON_WHATSAPP_TTL:
|
||||
(Number.parseInt(process.env?.CACHE_REDIS_SAVE_IS_ON_WHATSAPP_TTL) || 7) * 24 * 60 * 60,
|
||||
},
|
||||
LOCAL: {
|
||||
ENABLED: process.env?.CACHE_LOCAL_ENABLED === 'true',
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { cache, prismaRepository } from '@api/server.module';
|
||||
import { CacheConf, configService, Database } from '@config/env.config';
|
||||
import { prismaRepository } from '@api/server.module';
|
||||
import { configService, Database } from '@config/env.config';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
function getAvailableNumbers(remoteJid: string) {
|
||||
@ -54,23 +54,6 @@ interface ISaveOnWhatsappCacheParams {
|
||||
remoteJid: string;
|
||||
}
|
||||
export async function saveOnWhatsappCache(data: ISaveOnWhatsappCacheParams[]) {
|
||||
const cacheConfig = configService.get<CacheConf>('CACHE');
|
||||
|
||||
if (cacheConfig.REDIS.ENABLED && cacheConfig.REDIS.SAVE_IS_ON_WHATSAPP) {
|
||||
await Promise.all(
|
||||
data.map(async (item) => {
|
||||
const remoteJid = item.remoteJid.startsWith('+') ? item.remoteJid.slice(1) : item.remoteJid;
|
||||
const numbersAvailable = getAvailableNumbers(remoteJid);
|
||||
|
||||
await cache.set(
|
||||
`isOnWhatsapp:${remoteJid}`,
|
||||
JSON.stringify({ jidOptions: numbersAvailable }),
|
||||
cacheConfig.REDIS.SAVE_IS_ON_WHATSAPP_TTL,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (configService.get<Database>('DATABASE').SAVE_DATA.IS_ON_WHATSAPP) {
|
||||
const upsertsQuery = data.map((item) => {
|
||||
const remoteJid = item.remoteJid.startsWith('+') ? item.remoteJid.slice(1) : item.remoteJid;
|
||||
@ -88,48 +71,14 @@ export async function saveOnWhatsappCache(data: ISaveOnWhatsappCacheParams[]) {
|
||||
}
|
||||
|
||||
export async function getOnWhatsappCache(remoteJids: string[]) {
|
||||
const cacheConfig = configService.get<CacheConf>('CACHE');
|
||||
|
||||
const results: {
|
||||
let results: {
|
||||
remoteJid: string;
|
||||
number: string;
|
||||
jidOptions: string[];
|
||||
}[] = [];
|
||||
|
||||
if (cacheConfig.REDIS.ENABLED && cacheConfig.REDIS.SAVE_IS_ON_WHATSAPP) {
|
||||
const data = await Promise.all(
|
||||
remoteJids.map(async (remoteJid) => {
|
||||
const remoteJidWithoutPlus = remoteJid.startsWith('+') ? remoteJid.slice(1) : remoteJid;
|
||||
const cacheData = await cache.get(`isOnWhatsapp:${remoteJidWithoutPlus}`);
|
||||
|
||||
if (cacheData) {
|
||||
return {
|
||||
remoteJid: remoteJidWithoutPlus,
|
||||
number: remoteJidWithoutPlus.split('@')[0],
|
||||
jidOptions: JSON.parse(cacheData)?.jidOptions,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}),
|
||||
);
|
||||
|
||||
data.forEach((item) => {
|
||||
if (item) {
|
||||
results.push({
|
||||
remoteJid: item.remoteJid,
|
||||
number: item.number,
|
||||
jidOptions: item.jidOptions,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (configService.get<Database>('DATABASE').SAVE_DATA.IS_ON_WHATSAPP) {
|
||||
const remoteJidsWithoutPlus = remoteJids
|
||||
.filter((remoteJid) => !results.some((result) => result.remoteJid === remoteJid))
|
||||
.map((remoteJid) => getAvailableNumbers(remoteJid))
|
||||
.flat();
|
||||
const remoteJidsWithoutPlus = remoteJids.map((remoteJid) => getAvailableNumbers(remoteJid)).flat();
|
||||
|
||||
const onWhatsappCache = await prismaRepository.isOnWhatsapp.findMany({
|
||||
where: {
|
||||
@ -140,13 +89,11 @@ export async function getOnWhatsappCache(remoteJids: string[]) {
|
||||
},
|
||||
});
|
||||
|
||||
onWhatsappCache.forEach((item) =>
|
||||
results.push({
|
||||
remoteJid: item.remoteJid,
|
||||
number: item.remoteJid.split('@')[0],
|
||||
jidOptions: item.jidOptions.split(','),
|
||||
}),
|
||||
);
|
||||
results = onWhatsappCache.map((item) => ({
|
||||
remoteJid: item.remoteJid,
|
||||
number: item.remoteJid.split('@')[0],
|
||||
jidOptions: item.jidOptions.split(','),
|
||||
}));
|
||||
}
|
||||
|
||||
return results;
|
||||
|
Loading…
Reference in New Issue
Block a user