Alteração para que o cache seja atualizado apos o bulk insert de contactos
commit
82f0f107f4
|
@ -13,7 +13,8 @@ import CheckIsValidContact from "../services/WbotServices/CheckIsValidContact";
|
|||
import GetProfilePicUrl from "../services/WbotServices/GetProfilePicUrl";
|
||||
import AppError from "../errors/AppError";
|
||||
|
||||
import { searchContactCache } from '../helpers/ContactsCache'
|
||||
import { searchContactCache, insertContactsCache } from '../helpers/ContactsCache'
|
||||
|
||||
import { off } from "process";
|
||||
|
||||
import GetContactService from "../services/ContactServices/GetContactService";
|
||||
|
@ -233,7 +234,7 @@ export const contacsBulkInsertOnQueue = async (req: Request, res: Response): Pro
|
|||
|
||||
// console.log('THE BODY: ', req.body)
|
||||
|
||||
const { adminId, identifier, queueStatus, file } = req.body
|
||||
const { adminId, identifier, queueStatus, file, contacts_inserted } = req.body
|
||||
|
||||
const io = getIO();
|
||||
io.emit("contactsBulkInsertOnQueueStatus", {
|
||||
|
@ -246,6 +247,13 @@ export const contacsBulkInsertOnQueue = async (req: Request, res: Response): Pro
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
if (process.env.CACHE && contacts_inserted) {
|
||||
|
||||
await insertContactsCache(contacts_inserted)
|
||||
|
||||
}
|
||||
|
||||
return res.status(200).json({ message: 'ok' })
|
||||
};
|
||||
|
||||
|
|
|
@ -162,6 +162,28 @@ const escapeCharCache = (str: string) => {
|
|||
|
||||
}
|
||||
|
||||
const insertContactsCache = async (contacts: any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const pipeline = redis.pipeline()
|
||||
|
||||
for (let i = 0; i < contacts.length; i++) {
|
||||
|
||||
contacts[i].escaped_name = escapeCharCache(contacts[i].name)
|
||||
|
||||
pipeline.hmset(`contact:${contacts[i].id}`, contacts[i]);
|
||||
}
|
||||
|
||||
await pipeline.exec(() => { console.log(`${contacts.length} CONTACTS INSERTED IN CACHE!`) });
|
||||
|
||||
redis.quit()
|
||||
}
|
||||
|
||||
const loadContactsCache = async () => {
|
||||
|
||||
await createContactIndexCache('idx_contact')
|
||||
|
@ -225,5 +247,6 @@ export {
|
|||
deleteContactsByIdCache,
|
||||
updateContactCacheById,
|
||||
createOrUpdateContactCache,
|
||||
escapeCharCache
|
||||
escapeCharCache,
|
||||
insertContactsCache
|
||||
}
|
Loading…
Reference in New Issue