add cache interceptor for hot endpoints
deploy to danak / build_and_deploy (push) Has been cancelled
deploy to danak / build_and_deploy (push) Has been cancelled
This commit is contained in:
@@ -27,6 +27,8 @@ import { Schedule } from '../entities/schedule.entity';
|
||||
import { WalletTransaction } from '../../users/entities/wallet-transaction.entity';
|
||||
import { SmsLog } from '../../notifications/entities/smsLogs.entity';
|
||||
import { Notification } from '../../notifications/entities/notification.entity';
|
||||
import { CacheService } from 'src/modules/utils/cache.service';
|
||||
import { CacheKeys } from 'src/common/constants/cache-keys.constant';
|
||||
|
||||
|
||||
@Injectable()
|
||||
@@ -34,6 +36,7 @@ export class RestaurantsService {
|
||||
constructor(
|
||||
private readonly em: EntityManager,
|
||||
private readonly restRepository: RestRepository,
|
||||
private readonly cacheService: CacheService,
|
||||
) { }
|
||||
|
||||
async setupRestuarant(dto: CreateRestaurantDto): Promise<Restaurant> {
|
||||
@@ -184,13 +187,28 @@ export class RestaurantsService {
|
||||
|
||||
}
|
||||
|
||||
const previousSlug = restaurant.slug;
|
||||
this.restRepository.assign(restaurant, dto);
|
||||
|
||||
await this.em.persistAndFlush(restaurant);
|
||||
|
||||
await this.invalidateRestaurantCache(previousSlug);
|
||||
if (restaurant.slug !== previousSlug) {
|
||||
await this.invalidateRestaurantCache(restaurant.slug);
|
||||
}
|
||||
|
||||
return restaurant;
|
||||
}
|
||||
|
||||
private async invalidateRestaurantCache(slug?: string): Promise<void> {
|
||||
if (!slug) return;
|
||||
await Promise.all([
|
||||
this.cacheService.del(CacheKeys.restaurantSpec(slug)),
|
||||
this.cacheService.del(CacheKeys.foodsByRestaurant(slug)),
|
||||
this.cacheService.del(CacheKeys.categoriesByRestaurant(slug)),
|
||||
]);
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
// Soft delete the restaurant by setting isActive to false
|
||||
const restaurant = await this.restRepository.findOne({ id });
|
||||
|
||||
Reference in New Issue
Block a user