Skip to content

Commit

Permalink
Merge pull request #160 from LocalMingle/jonghwa
Browse files Browse the repository at this point in the history
검색 기능 캐싱 롤백
  • Loading branch information
kimjonghwa230412 authored Nov 6, 2023
2 parents 69039c2 + 6969c04 commit ec46902
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/searches/searches.service.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { Inject, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
import { SearchesDto } from './searches.dto/searches.dto';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Cache } from 'cache-manager';

@Injectable()
export class SearchesService {
constructor(
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
private readonly prisma: PrismaService
) {}

async search(searchesDto: SearchesDto) {
const searchedEvents: any = await this.cacheManager.get('searchedEvents');
const cachedData = searchedEvents ? searchedEvents : null;
if (cachedData) {
return cachedData;
} else {
const events = await this.prisma.event.findMany({
return await this.prisma.event.findMany({
where: {
isDeleted: false,
AND: [
Expand Down Expand Up @@ -64,8 +56,5 @@ export class SearchesService {
createdAt: 'desc',
},
});
await this.cacheManager.set('searchedEvents', events);
return events;
}
}
}

0 comments on commit ec46902

Please sign in to comment.