Alteração no .env para ativar ou desativar o recurso de busca por cache
parent
9bf1850405
commit
e83f46ae08
|
@ -39,7 +39,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||
let { searchParam, pageNumber } = req.query as IndexQuery;
|
||||
|
||||
// TEST DEL
|
||||
if (searchParam && searchParam.trim().length > 0) {
|
||||
if (searchParam && searchParam.trim().length > 0 && process.env.CACHE) {
|
||||
|
||||
try {
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@ import { redisConn } from './TicketCache'
|
|||
const deleteContactsByIdCache = async (id: string | number) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const contact_cache: any = await redis.hgetall(`contact:${id}`)
|
||||
|
@ -34,6 +37,9 @@ const deleteContactsByIdCache = async (id: string | number) => {
|
|||
const updateContactCache = async (hash: any, json_object: any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const pipeline = redis.pipeline()
|
||||
|
@ -53,6 +59,9 @@ const updateContactCache = async (hash: any, json_object: any) => {
|
|||
const updateContactCacheById = async (id: string | number, update_fields: object | any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const contact_cache: any = await redis.hgetall(`contact:${id}`)
|
||||
|
@ -81,6 +90,9 @@ const updateContactCacheById = async (id: string | number, update_fields: object
|
|||
const createOrUpdateContactCache = async (hash: any, contact: any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
if (contact.name) {
|
||||
|
@ -97,6 +109,9 @@ const createOrUpdateContactCache = async (hash: any, contact: any) => {
|
|||
async function searchContactCache(search: string, offset: number, limit: number) {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return null
|
||||
|
||||
search = escapeCharCache(search)
|
||||
|
@ -152,6 +167,9 @@ const loadContactsCache = async () => {
|
|||
await createContactIndexCache('idx_contact')
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
let contacts = await ListContactsServiceCache()
|
||||
|
@ -177,6 +195,8 @@ const createContactIndexCache = async (hashIndex: string) => {
|
|||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
try {
|
||||
|
|
|
@ -9,6 +9,10 @@ import { escapeCharCache } from './ContactsCache'
|
|||
|
||||
|
||||
const redisConn = async () => {
|
||||
|
||||
if(!process.env.CACHE){
|
||||
return null
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
|
@ -49,7 +53,9 @@ const redisConn = async () => {
|
|||
|
||||
const flushCache = async () => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return false
|
||||
|
||||
if (redis.status === 'connect') {
|
||||
|
||||
|
@ -64,6 +70,8 @@ const cacheSize = async () => {
|
|||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return null
|
||||
|
||||
if (redis.status !== 'connect') {
|
||||
return -1
|
||||
}
|
||||
|
@ -78,6 +86,8 @@ const loadTicketsCache = async () => {
|
|||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
await createTicketIndexCache('idx_ticket')
|
||||
|
@ -112,6 +122,8 @@ const createTicketIndexCache = async (hashIndex: string) => {
|
|||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
try {
|
||||
|
@ -138,6 +150,8 @@ const updateTicketCache = async (hash: any, json_object: any) => {
|
|||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const pipeline = redis.pipeline()
|
||||
|
@ -156,6 +170,9 @@ const updateTicketCache = async (hash: any, json_object: any) => {
|
|||
const updateTicketCacheByTicketId = async (ticketId: string | number, update_fields: any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const ticket_cache = await redis.hgetall(`ticket:${ticketId}`)
|
||||
|
@ -187,6 +204,9 @@ const updateTicketCacheByTicketId = async (ticketId: string | number, update_fie
|
|||
const createOrUpdateTicketCache = async (hash: any, ticket: any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
@ -207,6 +227,9 @@ const createOrUpdateTicketCache = async (hash: any, ticket: any) => {
|
|||
const deleteTicketsByIdCache = async (ticketId: string | number) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const ticket_cache = await redis.hgetall(`ticket:${ticketId}`)
|
||||
|
@ -232,6 +255,9 @@ const deleteTicketsByIdCache = async (ticketId: string | number) => {
|
|||
const deleteTicketsFieldsCache = async (tickets: any, del_fields: any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const pipeline = redis.pipeline()
|
||||
|
@ -261,6 +287,9 @@ const deleteTicketsFieldsCache = async (tickets: any, del_fields: any) => {
|
|||
const updateTicketsByContactsCache = async (oldNumber: string, newName: string, newNumber: string) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const pipeline = redis.pipeline()
|
||||
|
@ -295,6 +324,9 @@ const updateTicketsByContactsCache = async (oldNumber: string, newName: string,
|
|||
const deleteTicketsByContactsCache = async (number: string) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
const pipeline = redis.pipeline()
|
||||
|
@ -324,6 +356,9 @@ const deleteTicketsByContactsCache = async (number: string) => {
|
|||
const deleteTicketCache = async (hash: any) => {
|
||||
|
||||
const redis: any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if (redis.status !== 'connect') return
|
||||
|
||||
await redis.del(hash)
|
||||
|
@ -333,7 +368,9 @@ const deleteTicketCache = async (hash: any) => {
|
|||
|
||||
async function searchTicketCache(search: string, offset?: number, limit?: number) {
|
||||
|
||||
const redis:any = await redisConn();
|
||||
const redis:any = await redisConn();
|
||||
|
||||
if(!redis) return
|
||||
|
||||
if(redis.status!=='connect') return null
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ gracefulShutdown(server);
|
|||
|
||||
const cacheLength = await cacheSize()
|
||||
|
||||
console.log('cacheSize: ', cacheLength)
|
||||
|
||||
if(cacheLength == 0){
|
||||
console.log('Loading from cache...')
|
||||
await flushCache()
|
||||
|
|
|
@ -53,7 +53,7 @@ const ListTicketsService = async ({
|
|||
|
||||
let whereCondition: Filterable["where"] = { [Op.or]: [{ userId }, { status: "pending" }], queueId: { [Op.or]: [queueIds, null] } };
|
||||
|
||||
if (searchParam && searchParam.trim().length > 0) {
|
||||
if (searchParam && searchParam.trim().length > 0 && process.env.CACHE) {
|
||||
|
||||
try {
|
||||
|
||||
|
|
Loading…
Reference in New Issue