From ce5cc79e212e84d932f080de0088cbf01a05e05b Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Tue, 16 Dec 2025 10:32:21 +0000 Subject: [PATCH 1/2] refactor: remove unused cache options and related methods from Cacher class --- backend/src/helpers/cache/cacher.ts | 132 --------------------- backend/src/helpers/constants/constants.ts | 22 ---- 2 files changed, 154 deletions(-) diff --git a/backend/src/helpers/cache/cacher.ts b/backend/src/helpers/cache/cacher.ts index 9392340d..b0a32c2c 100644 --- a/backend/src/helpers/cache/cacher.ts +++ b/backend/src/helpers/cache/cacher.ts @@ -1,19 +1,8 @@ -import { ForeignKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/foreign-key.ds.js'; -import { PrimaryKeyDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/primary-key.ds.js'; -import { TableStructureDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/table-structure.ds.js'; -import { Knex } from 'knex'; import { LRUCache } from 'lru-cache'; -import { ConnectionEntity } from '../../entities/connection/connection.entity.js'; import { isSaaS } from '../app/is-saas.js'; import { Constants } from '../constants/constants.js'; -const knexCache = new LRUCache(Constants.DEFAULT_CONNECTION_CACHE_OPTIONS); -const tunnelCache = new LRUCache(Constants.DEFAULT_TUNNEL_CACHE_OPTIONS); -const driverCache = new LRUCache(Constants.DEFAULT_DRIVER_CACHE_OPTIONS); const invitationCache = new LRUCache(Constants.DEFAULT_INVITATION_CACHE_OPTIONS); -const tableStructureCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS); -const tableForeignKeysCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS); -const tablePrimaryKeysCache = new LRUCache(Constants.DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS); const tableReadPermissionCache = new LRUCache(Constants.DEFAULT_TABLE_PERMISSIONS_CACHE_OPTIONS); export class Cacher { @@ -76,129 +65,8 @@ export class Cacher { return userInvitations <= 10 && groupInvitations <= 10; } - public static getCachedKnex(connectionConfig): Knex { - const cachedKnex = knexCache.get(JSON.stringify(connectionConfig)) as Knex; - return cachedKnex ? cachedKnex : null; - } - - public static setKnexCache(connectionConfig, newKnex: Knex): void { - knexCache.set(JSON.stringify(connectionConfig), newKnex); - } - - public static getTunnelCache(connection: ConnectionEntity): any { - const cachedTnl = tunnelCache.get(JSON.stringify(connection)); - return cachedTnl ? cachedTnl : null; - } - - public static setTunnelCache(connection: ConnectionEntity, tnlObj): void { - tunnelCache.set(JSON.stringify(connection), tnlObj); - } - - public static delTunnelCache(connection: ConnectionEntity): void { - tunnelCache.delete(JSON.stringify(connection)); - } - - public static getDriverCache(connection: ConnectionEntity): any { - const cachedDriver = driverCache.get(JSON.stringify(connection)); - return cachedDriver ? cachedDriver : null; - } - - public static setDriverCache(connection: ConnectionEntity, newDriver): void { - driverCache.set(JSON.stringify(connection), newDriver); - } - - public static delDriverCache(connection: ConnectionEntity): void { - driverCache.delete(JSON.stringify(connection)); - } - - public static setTableStructureCache( - connection: ConnectionEntity, - tableName: string, - structure: Array, - ): void { - const connectionCopy = { - ...connection, - }; - const cacheObj = JSON.stringify({ connectionCopy, tableName }); - tableStructureCache.set(cacheObj, structure); - } - - public static getTableStructureCache(connection: ConnectionEntity, tableName: string): Array { - const connectionCopy = { - ...connection, - }; - const cacheObj = JSON.stringify({ connectionCopy, tableName }); - const foundStructure = tableStructureCache.get(cacheObj) as Array; - return foundStructure ? foundStructure : null; - } - - public static setTablePrimaryKeysCache( - connection: ConnectionEntity, - tableName: string, - primaryKeys: Array, - ): void { - const connectionCopy = { - ...connection, - }; - const cacheObj = JSON.stringify({ connectionCopy, tableName }); - tablePrimaryKeysCache.set(cacheObj, primaryKeys); - } - - public static getTablePrimaryKeysCache(connection: ConnectionEntity, tableName: string): Array { - const connectionCopy = { - ...connection, - }; - const cacheObj = JSON.stringify({ connectionCopy, tableName }); - const foundKeys = tablePrimaryKeysCache.get(cacheObj) as Array; - return foundKeys ? foundKeys : null; - } - - public static setTableForeignKeysCache( - connection: ConnectionEntity, - tableName: string, - foreignKeys: Array, - ): void { - const connectionCopy = { - ...connection, - }; - const cacheObj = JSON.stringify({ connectionCopy, tableName }); - tableForeignKeysCache.set(cacheObj, foreignKeys); - } - - public static getTableForeignKeysCache(connection: ConnectionEntity, tableName: string): Array { - const connectionCopy = { - ...connection, - }; - const cacheObj = JSON.stringify({ connectionCopy, tableName }); - const foundKeys = tableForeignKeysCache.get(cacheObj) as Array; - return foundKeys ? foundKeys : null; - } - public static async clearAllCache(): Promise { - const elements = []; - knexCache.forEach((value, key) => { - elements.push({ key, value }); - }); - for (const element of elements) { - await element.value.destroy(); - knexCache.delete(element.key); - } - knexCache.clear(); - - const tunnelElements = []; - tunnelCache.forEach((value, key) => { - tunnelElements.push({ key, value }); - }); - for (const element of tunnelElements) { - await element.value.close(); - tunnelCache.delete(element.key); - } - tunnelCache.clear(); - await driverCache.clear(); await invitationCache.clear(); - await tableStructureCache.clear(); - await tableForeignKeysCache.clear(); - await tablePrimaryKeysCache.clear(); await tableReadPermissionCache.clear(); } } diff --git a/backend/src/helpers/constants/constants.ts b/backend/src/helpers/constants/constants.ts index 195c7fdc..fa4f3e48 100644 --- a/backend/src/helpers/constants/constants.ts +++ b/backend/src/helpers/constants/constants.ts @@ -118,33 +118,11 @@ export const Constants = { }, }, - DEFAULT_TUNNEL_CACHE_OPTIONS: { - max: 100, - ttl: 1000 * 60 * 60, - dispose: async (tnl: any) => { - try { - await tnl.close(); - } catch (e) { - console.error('Tunnel closing error: ' + e); - } - }, - }, - - DEFAULT_DRIVER_CACHE_OPTIONS: { - max: 50, - ttl: 1000 * 60 * 60, - }, - DEFAULT_INVITATION_CACHE_OPTIONS: { max: 200, ttl: 1000 * 60 * 60, }, - DEFAULT_TABLE_STRUCTURE_ELEMENTS_CACHE_OPTIONS: { - max: 1000, - ttl: 1000 * 60, - }, - DEFAULT_TABLE_PERMISSIONS_CACHE_OPTIONS: { max: 1000, ttl: 1000 * 10, From 123e51e696b24fe255cb66d72b9972625655058f Mon Sep 17 00:00:00 2001 From: Artem Niehrieiev Date: Tue, 16 Dec 2025 11:17:53 +0000 Subject: [PATCH 2/2] refactor: remove unused dependencies and update node-gyp version in package.json and yarn.lock --- backend/package.json | 11 ----------- shared-code/package.json | 3 ++- yarn.lock | 6 +----- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/backend/package.json b/backend/package.json index 6281faa6..79d59303 100644 --- a/backend/package.json +++ b/backend/package.json @@ -6,13 +6,6 @@ "private": true, "license": "UNLICENSED", "type": "module", - "packageExtensions": { - "ibm_db": { - "dependencies": { - "node-gyp": "^11.5.0" - } - } - }, "scripts": { "prebuild": "rimraf dist", "build": "nest build", @@ -80,7 +73,6 @@ "knex": "3.1.0", "lru-cache": "^11.2.2", "nanoid": "5.1.6", - "node-gyp": "^11.5.0", "nodemailer": "^7.0.10", "nunjucks": "^3.2.4", "openai": "^6.7.0", @@ -100,9 +92,6 @@ "validator": "^13.15.20", "winston": "3.18.3" }, - "optionalDependencies": { - "ibm_db": "3.3.0" - }, "devDependencies": { "@ava/typescript": "6.0.0", "@nestjs/cli": "^11.0.10", diff --git a/shared-code/package.json b/shared-code/package.json index cfad6ca8..f202c6fd 100644 --- a/shared-code/package.json +++ b/shared-code/package.json @@ -6,7 +6,7 @@ "packageExtensions": { "ibm_db": { "dependencies": { - "node-gyp": "^10.2.0" + "node-gyp": "^11.5.0" } } }, @@ -29,6 +29,7 @@ "mongodb": "^6.20.0", "mysql2": "^3.15.3", "nanoid": "^5.1.6", + "node-gyp": "^11.5.0", "oracledb": "^6.10.0", "p-queue": "^9.0.0", "pg": "^8.16.3", diff --git a/yarn.lock b/yarn.lock index dea2997e..ec1bfbfb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3068,6 +3068,7 @@ __metadata: mongodb: ^6.20.0 mysql2: ^3.15.3 nanoid: ^5.1.6 + node-gyp: ^11.5.0 oracledb: ^6.10.0 p-queue: ^9.0.0 pg: ^8.16.3 @@ -5226,7 +5227,6 @@ __metadata: fetch-blob: ^4.0.0 helmet: 8.1.0 i18n-iso-countries: ^7.14.0 - ibm_db: 3.3.0 ip-range-check: 0.2.0 json2csv: ^5.0.7 jsonwebtoken: ^9.0.2 @@ -5235,7 +5235,6 @@ __metadata: lru-cache: ^11.2.2 nanoid: 5.1.6 nock: ^14.0.10 - node-gyp: ^11.5.0 nodemailer: ^7.0.10 nunjucks: ^3.2.4 openai: ^6.7.0 @@ -5260,9 +5259,6 @@ __metadata: uuid: ^13.0.0 validator: ^13.15.20 winston: 3.18.3 - dependenciesMeta: - ibm_db: - optional: true languageName: unknown linkType: soft