From 3f5be688ecd862d5266e12900e52f51d93015e4b Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sun, 15 Mar 2026 15:37:43 +0330 Subject: [PATCH] remove unused modules --- package.json | 11 ++----- src/app.module.ts | 3 -- src/config/cache.config.ts | 27 ---------------- src/modules/utils/cache.service.ts | 52 ------------------------------ src/modules/utils/utils.module.ts | 5 ++- 5 files changed, 5 insertions(+), 93 deletions(-) delete mode 100755 src/config/cache.config.ts delete mode 100755 src/modules/utils/cache.service.ts diff --git a/package.json b/package.json index 598d19c..3703f24 100644 --- a/package.json +++ b/package.json @@ -37,15 +37,13 @@ "@fastify/cookie": "^11.0.2", "@fastify/multipart": "^9.3.0", "@fastify/static": "^8.3.0", - "@keyv/redis": "^5.1.3", - "@mikro-orm/core": "^6.5.8", + "@mikro-orm/core": "^6.5.8", "@mikro-orm/nestjs": "^6.1.1", "@mikro-orm/postgresql": "^6.5.8", "@nest-lab/fastify-multer": "^1.3.0", "@nestjs/axios": "^4.0.1", "@nestjs/bullmq": "^11.0.4", - "@nestjs/cache-manager": "^3.0.1", - "@nestjs/common": "^11.0.1", + "@nestjs/common": "^11.0.1", "@nestjs/config": "^4.0.2", "@nestjs/core": "^11.0.1", "@nestjs/event-emitter": "^3.0.1", @@ -59,10 +57,7 @@ "@nestjs/throttler": "^6.4.0", "@types/socket.io": "^3.0.1", "axios": "^1.13.1", - "bullmq": "^5.65.1", - "cache-manager": "^7.2.4", - "cacheable": "^2.3.1", - "class-transformer": "^0.5.1", + "class-transformer": "^0.5.1", "class-validator": "^0.14.2", "dayjs": "^1.11.19", "fastify": "^5.6.1", diff --git a/src/app.module.ts b/src/app.module.ts index c0dd93c..d6b83ec 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -9,15 +9,12 @@ import { AdminModule } from './modules/admin/admin.module'; import { ThrottlerModule } from '@nestjs/throttler'; import { ScheduleModule } from '@nestjs/schedule'; import { EventEmitterModule } from '@nestjs/event-emitter'; -import { CacheModule } from '@nestjs/cache-manager'; -import { cacheConfig } from './config/cache.config'; import { BusinessModule } from './modules/business/business.module'; import { CatalogueModule } from './modules/catalogue/catalogue.module'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, cache: true }), - CacheModule.registerAsync(cacheConfig()), MikroOrmModule.forRootAsync(dataBaseConfig), UtilsModule, AuthModule, diff --git a/src/config/cache.config.ts b/src/config/cache.config.ts deleted file mode 100755 index c2134ea..0000000 --- a/src/config/cache.config.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Keyv } from 'keyv'; -import KeyvRedis from '@keyv/redis'; -import type { CacheModuleAsyncOptions } from '@nestjs/cache-manager'; -import { ConfigService } from '@nestjs/config'; -import { CacheableMemory } from 'cacheable'; - -export function cacheConfig(): CacheModuleAsyncOptions { - return { - isGlobal: true, - inject: [ConfigService], - useFactory: async (configService: ConfigService) => { - const redisUri = configService.get('REDIS_URI'); - const namespace = configService.get('CACHE_NAMESPACE', 'app-cache'); - const ttl = +configService.get('CACHE_TTL', 3600); //1 hour - - return { - stores: [ - new Keyv({ - store: new CacheableMemory({ ttl: ttl * 1000, lruSize: 5000 }), - namespace: namespace - }), - new KeyvRedis(redisUri, { namespace: namespace }), - ], - }; - }, - }; -} \ No newline at end of file diff --git a/src/modules/utils/cache.service.ts b/src/modules/utils/cache.service.ts deleted file mode 100755 index b9e7a32..0000000 --- a/src/modules/utils/cache.service.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { CACHE_MANAGER, Cache } from '@nestjs/cache-manager'; -import { Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common'; - -@Injectable() -export class CacheService implements OnModuleInit { - private readonly logger = new Logger(CacheService.name); - - constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {} - - async onModuleInit() { -; - this.logger.log(`Active Cache Store: ${JSON.stringify(this.cacheManager as any)}`); - - // Should log 'Keyv' or 'KeyvRedis'. If it says 'Memory', the config is still wrong. - this.logger.log('Pinging Redis to check connection...'); - try { - await this.set('ping', 'pong', 10); // TTL in seconds - const result = await this.get('ping'); - - if (result === 'pong') { - this.logger.log('✅ Redis connection successful (set/get test passed).'); - } else { - this.logger.error(`❌ Redis connection test failed. Expected 'pong', got '${result}'.`); - } - - await this.del('ping'); - } catch (error: any) { - this.logger.error('❌ Failed to connect to Redis during ping test:', error.message); - } - } - - /** Get value from cache */ - async get(key: string): Promise { - return await this.cacheManager.get(key); - } - - /** Set value in cache with TTL in seconds */ - async set(key: string, value: any, ttlSeconds: number) { - // cache-manager expects TTL in seconds - await this.cacheManager.set(key, value, ttlSeconds * 1000); - } - - /** Delete a key from cache */ - async del(key: string) { - await this.cacheManager.del(key); - } - - /** Get remaining TTL in seconds */ - async getTtl(key: string): Promise { - return await this.cacheManager.ttl(key); - } -} diff --git a/src/modules/utils/utils.module.ts b/src/modules/utils/utils.module.ts index 2f7cef5..ef5fdaf 100644 --- a/src/modules/utils/utils.module.ts +++ b/src/modules/utils/utils.module.ts @@ -1,11 +1,10 @@ import { Module } from '@nestjs/common'; -import { CacheService } from './cache.service'; @Module({ imports: [], controllers: [], - providers: [CacheService, ], - exports: [CacheService], + providers: [ ], + exports: [], }) export class UtilsModule {}