@@ -56,6 +56,9 @@ import type {
5656 WorkflowDeleteEvent ,
5757 WorkflowUpdateEvent ,
5858} from '../../event-emitter/events/workflow/workflow.event' ;
59+ import { generateBaseNodeListCacheKey } from '../../performance-cache/generate-keys' ;
60+ import { PerformanceCacheService } from '../../performance-cache/service' ;
61+ import type { IPerformanceCacheStore } from '../../performance-cache/types' ;
5962import { ShareDbService } from '../../share-db/share-db.service' ;
6063import type { IClsStore } from '../../types/cls' ;
6164import { updateOrder } from '../../utils/update-order' ;
@@ -104,6 +107,7 @@ const maxFolderDepth = 2;
104107export class BaseNodeService {
105108 private readonly logger = new Logger ( BaseNodeService . name ) ;
106109 constructor (
110+ private readonly performanceCacheService : PerformanceCacheService < IPerformanceCacheStore > ,
107111 private readonly prismaService : PrismaService ,
108112 @InjectModel ( 'CUSTOM_KNEX' ) private readonly knex : Knex ,
109113 private readonly cls : ClsService < IClsStore > ,
@@ -168,6 +172,7 @@ export class BaseNodeService {
168172 | IBaseNodePresenceUpdatePayload
169173 | IBaseNodePresenceDeletePayload ,
170174 > ( baseId : string , handler : ( presence : LocalPresence < T > ) => void ) {
175+ this . performanceCacheService . del ( generateBaseNodeListCacheKey ( baseId ) ) ;
171176 const channel = getBaseNodeChannel ( baseId ) ;
172177 const presence = this . shareDbService . connect ( ) . getPresence ( channel ) ;
173178 const localPresence = presence . create ( channel ) ;
@@ -234,7 +239,7 @@ export class BaseNodeService {
234239 ] ;
235240 }
236241
237- async prepareTree ( baseId : string ) : Promise < IBaseNodeVo [ ] > {
242+ async prepareNodeList ( baseId : string ) : Promise < IBaseNodeVo [ ] > {
238243 const resourceTypes = this . getResourceTypes ( ) ;
239244 const resourceResults = await Promise . all (
240245 resourceTypes . map ( ( type ) => this . getNodeResource ( baseId , type ) )
@@ -336,12 +341,23 @@ export class BaseNodeService {
336341 ) ;
337342 }
338343
344+ async getNodeListWithCache ( baseId : string ) : Promise < IBaseNodeVo [ ] > {
345+ return this . performanceCacheService . wrap (
346+ generateBaseNodeListCacheKey ( baseId ) ,
347+ ( ) => this . prepareNodeList ( baseId ) ,
348+ {
349+ ttl : 60 * 60 , // 1 hour
350+ statsType : 'base-node-list' ,
351+ }
352+ ) ;
353+ }
354+
339355 async getList ( baseId : string ) : Promise < IBaseNodeVo [ ] > {
340- return this . prepareTree ( baseId ) ;
356+ return this . getNodeListWithCache ( baseId ) ;
341357 }
342358
343359 async getTree ( baseId : string ) : Promise < IBaseNodeTreeVo > {
344- const nodes = await this . prepareTree ( baseId ) ;
360+ const nodes = await this . getNodeListWithCache ( baseId ) ;
345361
346362 return {
347363 nodes,
@@ -805,12 +821,11 @@ export class BaseNodeService {
805821 return ;
806822 }
807823
808- await this . prismaService . $tx ( async ( prisma ) => {
824+ const createNode = async ( prisma : PrismaService ) => {
809825 const findNode = await prisma . baseNode . findFirst ( {
810826 where : { baseId, resourceType, resourceId } ,
811827 } ) ;
812828 if ( findNode ) {
813- this . logger . warn ( 'Base node already exists' , event ) ;
814829 return ;
815830 }
816831 const maxOrder = await this . getMaxOrder ( baseId ) ;
@@ -825,7 +840,8 @@ export class BaseNodeService {
825840 createdBy : userId || ANONYMOUS_USER_ID ,
826841 } ,
827842 } ) ;
828- } ) ;
843+ } ;
844+ await createNode ( this . prismaService ) ;
829845
830846 this . presenceHandler ( baseId , ( presence ) => {
831847 presence . submit ( {
@@ -970,12 +986,11 @@ export class BaseNodeService {
970986 return ;
971987 }
972988
973- await this . prismaService . $tx ( async ( prisma ) => {
989+ const deleteNode = async ( prisma : PrismaService ) => {
974990 const toDeleteNode = await prisma . baseNode . findFirst ( {
975991 where : { baseId, resourceType, resourceId } ,
976992 } ) ;
977993 if ( ! toDeleteNode ) {
978- this . logger . warn ( 'Base node has already been deleted' , event ) ;
979994 return ;
980995 }
981996 const maxOrder = await this . getMaxOrder ( baseId ) ;
@@ -997,7 +1012,8 @@ export class BaseNodeService {
9971012 } ) )
9981013 ) ;
9991014 }
1000- } ) ;
1015+ } ;
1016+ await deleteNode ( this . prismaService ) ;
10011017
10021018 this . presenceHandler ( baseId , ( presence ) => {
10031019 presence . submit ( {
0 commit comments