diff --git a/common/src/database-modules/database-server.ts b/common/src/database-modules/database-server.ts index e4c1da40c8..1f85274ec6 100644 --- a/common/src/database-modules/database-server.ts +++ b/common/src/database-modules/database-server.ts @@ -431,9 +431,9 @@ export class DatabaseServer extends AbstractDatabaseServer { criteria: FilterQuery, row: unknown | unknown[] ): Promise { - if(Array.isArray(criteria)) { - return await this.updateMany(entityClass, row as unknown as T[], criteria) as any - } + // if(Array.isArray(criteria)) { + // return await this.updateMany(entityClass, row as unknown as T[], criteria) as any + // } if (this.dryRun) { this.addDryRunId(entityClass, row); diff --git a/common/src/helpers/db-helper.ts b/common/src/helpers/db-helper.ts index 7751a6652d..617c12a495 100644 --- a/common/src/helpers/db-helper.ts +++ b/common/src/helpers/db-helper.ts @@ -767,8 +767,16 @@ export class DataBaseHelper extends AbstractDataBaseHelper entity: T | T[], filter?: FilterQuery ): Promise { + // if (Array.isArray(entity)) { + // return await Promise.all(entity.map(item => this.update(item))); + // } + if (Array.isArray(entity)) { - return await Promise.all(entity.map(item => this.update(item))); + const result = []; + for (const item of entity) { + result.push(await this.update(item)); + } + return result; } if (!entity.id && !entity._id && !filter) { diff --git a/guardian-service/src/api/contract.service.ts b/guardian-service/src/api/contract.service.ts index ca348ba1f7..08f8732f07 100644 --- a/guardian-service/src/api/contract.service.ts +++ b/guardian-service/src/api/contract.service.ts @@ -2464,7 +2464,7 @@ export async function contractAPI( ) < 0; } - await dataBaseServer.updateMany(RetirePool, pools); + await dataBaseServer.update(RetirePool, null, pools); const syncDate = new Date(); diff --git a/guardian-service/src/api/tag.service.ts b/guardian-service/src/api/tag.service.ts index eb98f32efe..8772248e0d 100644 --- a/guardian-service/src/api/tag.service.ts +++ b/guardian-service/src/api/tag.service.ts @@ -25,16 +25,17 @@ export async function publishSchemaTags( const messageServer = new MessageServer(root.hederaAccountId, root.hederaAccountKey, root.signOptions) .setTopicObject(topicConfig); - const tagObjects = [] + // const tagObjects = [] for (const tag of tags) { tag.target = schema.messageId; await publishTag(tag, messageServer, owner); - - tagObjects.push(tag); + await DatabaseServer.updateTag(tag); + // + // tagObjects.push(tag); } - await new DatabaseServer().updateTags(tagObjects); + // await new DatabaseServer().updateTags(tagObjects); } /** @@ -60,16 +61,17 @@ export async function publishPolicyTags( const messageServer = new MessageServer(root.hederaAccountId, root.hederaAccountKey, root.signOptions) .setTopicObject(topicConfig); - const tagObjects = [] + // const tagObjects = [] for (const tag of tags) { tag.target = policy.messageId; await publishTag(tag, messageServer, owner); + await DatabaseServer.updateTag(tag); - tagObjects.push(tag); + // tagObjects.push(tag); } - await new DatabaseServer().updateTags(tagObjects); + // await new DatabaseServer().updateTags(tagObjects); } /** @@ -95,16 +97,17 @@ export async function publishTokenTags( const messageServer = new MessageServer(root.hederaAccountId, root.hederaAccountKey, root.signOptions) .setTopicObject(topicConfig); - const tagObjects = [] + // const tagObjects = [] for (const tag of tags) { tag.target = token.tokenId; await publishTag(tag, messageServer, owner); + await DatabaseServer.updateTag(tag); - tagObjects.push(tag); + // tagObjects.push(tag); } - await new DatabaseServer().updateTags(tagObjects); + // await new DatabaseServer().updateTags(tagObjects); } /** @@ -129,16 +132,17 @@ export async function publishToolTags( const messageServer = new MessageServer(root.hederaAccountId, root.hederaAccountKey, root.signOptions) .setTopicObject(topicConfig); - const tagObjects = [] + // const tagObjects = [] for (const tag of tags) { tag.target = tool.tagsTopicId; await publishTag(tag, messageServer, owner); + await DatabaseServer.updateTag(tag); - tagObjects.push(tag); + // tagObjects.push(tag); } - await new DatabaseServer().updateTags(tagObjects); + // await new DatabaseServer().updateTags(tagObjects); } /** @@ -164,16 +168,17 @@ export async function publishModuleTags( const messageServer = new MessageServer(root.hederaAccountId, root.hederaAccountKey, root.signOptions) .setTopicObject(topicConfig); - const tagObjects = [] + // const tagObjects = [] for (const tag of tags) { tag.target = module.messageId; await publishTag(tag, messageServer, owner); + await DatabaseServer.updateTag(tag); - tagObjects.push(tag); + // tagObjects.push(tag); } - await new DatabaseServer().updateTags(tagObjects); + // await new DatabaseServer().updateTags(tagObjects); } /** @@ -485,7 +490,7 @@ export async function tagsAPI(logger: PinoLogger): Promise { map.set(tag.messageId, { message: null, local: tag }); } } - const tagObjects = [] + // const tagObjects = [] for (const item of map.values()) { if (item.message) { @@ -506,14 +511,15 @@ export async function tagsAPI(logger: PinoLogger): Promise { tag.date = tag.date || (new Date()).toISOString(); if (tag.id) { - tagObjects.push(tag); + // tagObjects.push(tag); + await DatabaseServer.updateTag(tag); } else { await DatabaseServer.createTag(tag); } } } - await new DatabaseServer().updateTags(tagObjects) + // await new DatabaseServer().updateTags(tagObjects) } } else { throw new Error('Invalid target'); @@ -523,15 +529,15 @@ export async function tagsAPI(logger: PinoLogger): Promise { const cache = await DatabaseServer.getTagCache(filter); if (cache.length) { - const tagCacheObjects = [] + // const tagCacheObjects = [] for (const item of cache) { item.date = date; - - tagCacheObjects.push(item); + await DatabaseServer.updateTagCache(item); + // tagCacheObjects.push(item); } - await DatabaseServer.updateTagsCache(tagCacheObjects) + // await DatabaseServer.updateTagsCache(tagCacheObjects) } else { await DatabaseServer.createTagCache({ localTarget, entity, date }); } diff --git a/guardian-service/src/policy-engine/helpers/policy-import-export-helper.ts b/guardian-service/src/policy-engine/helpers/policy-import-export-helper.ts index 3bb047289b..01124b1e4f 100644 --- a/guardian-service/src/policy-engine/helpers/policy-import-export-helper.ts +++ b/guardian-service/src/policy-engine/helpers/policy-import-export-helper.ts @@ -347,7 +347,7 @@ export class PolicyImport { for (const addedArtifact of this.artifactsResult.artifacts) { addedArtifact.policyId = policy.id; - await DatabaseServer.saveArtifact(addedArtifact); + // await DatabaseServer.saveArtifact(addedArtifact); artifactObjects.push(addedArtifact); } diff --git a/guardian-service/src/policy-engine/policy-engine.ts b/guardian-service/src/policy-engine/policy-engine.ts index db3c4e3ddf..73f3b4f828 100644 --- a/guardian-service/src/policy-engine/policy-engine.ts +++ b/guardian-service/src/policy-engine/policy-engine.ts @@ -756,7 +756,7 @@ export class PolicyEngine extends NatsService { const tokenIds = findAllEntities(model.config, ['tokenId']); const tokens = await DatabaseServer.getTokens({ tokenId: { $in: tokenIds }, owner: model.owner }); - const policyObjects = [] + // const policyObjects = [] for (const token of tokens) { let _token = token; @@ -769,10 +769,11 @@ export class PolicyEngine extends NatsService { replaceAllEntities(model.config, ['tokenId'], oldId, newToken.tokenId); replaceAllVariables(model.config, 'Token', oldId, newToken.tokenId); - policyObjects.push(model); + model = await DatabaseServer.updatePolicy(model); + // policyObjects.push(model); } - await DatabaseServer.savePolicies(policyObjects); + // await DatabaseServer.savePolicies(policyObjects); const tokenMessage = new TokenMessage(MessageAction.UseToken); tokenMessage.setDocument(_token); diff --git a/policy-service/src/policy-engine/blocks/tag-manager.ts b/policy-service/src/policy-engine/blocks/tag-manager.ts index 86d37331a1..730b370cd2 100644 --- a/policy-service/src/policy-engine/blocks/tag-manager.ts +++ b/policy-service/src/policy-engine/blocks/tag-manager.ts @@ -369,7 +369,7 @@ export class TagsManagerBlock { } } - const tagObjects = [] + // const tagObjects = [] for (const item of map.values()) { if (item.message) { @@ -390,14 +390,15 @@ export class TagsManagerBlock { tag.date = tag.date || (new Date()).toISOString(); if (tag.id) { - tagObjects.push(tag); + await ref.databaseServer.updateTag(tag); + // tagObjects.push(tag); } else { await ref.databaseServer.createTag(tag); } } } - await ref.databaseServer.updateTags(tagObjects) + // await ref.databaseServer.updateTags(tagObjects) } }