refactor: update caching and zap handling in components
- Replaced CacheInterceptor with HttpCacheInterceptor in app.module.ts for improved caching strategy. - Enhanced ContentDetailModal to dispatch a custom event upon zap completion, improving inter-component communication. - Refactored ContentRow to streamline zap stats fetching and added a listener for zap completion events, ensuring real-time updates. - Updated Analytics.vue to improve number formatting functions, handling undefined and null values more robustly. These changes enhance the application's performance and user experience by optimizing caching and ensuring accurate, real-time data updates across components.
This commit is contained in:
@@ -17,7 +17,8 @@ import { SubscriptionsModule } from './subscriptions/subscriptions.module';
|
||||
import { AwardIssuersModule } from './award-issuers/award-issuers.module';
|
||||
import { FestivalsModule } from './festivals/festivals.module';
|
||||
import { GenresModule } from './genres/genres.module';
|
||||
import { CacheInterceptor, CacheModule } from '@nestjs/cache-manager';
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import { HttpCacheInterceptor } from './common/interceptors/http-cache.interceptor';
|
||||
import { APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core';
|
||||
import { RentsModule } from './rents/rents.module';
|
||||
import { EventsModule } from './events/events.module';
|
||||
@@ -102,7 +103,7 @@ import { ZapsModule } from './zaps/zaps.module';
|
||||
AppService,
|
||||
{
|
||||
provide: APP_INTERCEPTOR,
|
||||
useClass: CacheInterceptor,
|
||||
useClass: HttpCacheInterceptor,
|
||||
},
|
||||
{
|
||||
provide: APP_FILTER,
|
||||
|
||||
18
backend/src/common/interceptors/http-cache.interceptor.ts
Normal file
18
backend/src/common/interceptors/http-cache.interceptor.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { CacheInterceptor } from '@nestjs/cache-manager';
|
||||
import { ExecutionContext, Injectable } from '@nestjs/common';
|
||||
|
||||
/**
|
||||
* Global cache interceptor that skips caching for paths that must stay fresh
|
||||
* (e.g. /zaps/stats so zap counts update after a user zaps).
|
||||
*/
|
||||
@Injectable()
|
||||
export class HttpCacheInterceptor extends CacheInterceptor {
|
||||
trackBy(context: ExecutionContext): string | undefined {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const path = request.url?.split('?')[0] ?? '';
|
||||
if (path.startsWith('/zaps') || path.startsWith('/api/zaps')) {
|
||||
return undefined;
|
||||
}
|
||||
return super.trackBy(context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user