Skip to content

Commit

Permalink
Revert "fix: delete update many[3966]"
Browse files Browse the repository at this point in the history
This reverts commit ebfa5f5.
  • Loading branch information
IharTsykala committed Sep 20, 2024
1 parent 998dbe7 commit 3a53696
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 51 deletions.
6 changes: 3 additions & 3 deletions common/src/database-modules/database-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ export class DatabaseServer extends AbstractDatabaseServer {
criteria: FilterQuery<T>,
row: unknown | unknown[]
): Promise<T> {
// 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);
Expand Down
10 changes: 1 addition & 9 deletions common/src/helpers/db-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,16 +767,8 @@ export class DataBaseHelper<T extends BaseEntity> extends AbstractDataBaseHelper
entity: T | T[],
filter?: FilterQuery<T>
): Promise<T | T[]> {
// if (Array.isArray(entity)) {
// return await Promise.all(entity.map(item => this.update(item)));
// }

if (Array.isArray(entity)) {
const result = [];
for (const item of entity) {
result.push(await this.update(item));
}
return result;
return await Promise.all(entity.map(item => this.update(item)));
}

if (!entity.id && !entity._id && !filter) {
Expand Down
2 changes: 1 addition & 1 deletion guardian-service/src/api/contract.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ export async function contractAPI(
) < 0;
}

await dataBaseServer.update(RetirePool, null, pools);
await dataBaseServer.updateMany(RetirePool, pools);

const syncDate = new Date();

Expand Down
52 changes: 23 additions & 29 deletions guardian-service/src/api/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ 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);
await DatabaseServer.updateTag(tag);
//
// tagObjects.push(tag);

tagObjects.push(tag);
}

// await new DatabaseServer().updateTags(tagObjects);
await new DatabaseServer().updateTags(tagObjects);
}

/**
Expand All @@ -61,17 +60,16 @@ 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);
}

/**
Expand All @@ -97,17 +95,16 @@ 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);
}

/**
Expand All @@ -132,17 +129,16 @@ 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);
}

/**
Expand All @@ -168,17 +164,16 @@ 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);
}

/**
Expand Down Expand Up @@ -490,7 +485,7 @@ export async function tagsAPI(logger: PinoLogger): Promise<void> {
map.set(tag.messageId, { message: null, local: tag });
}
}
// const tagObjects = []
const tagObjects = []

for (const item of map.values()) {
if (item.message) {
Expand All @@ -511,15 +506,14 @@ export async function tagsAPI(logger: PinoLogger): Promise<void> {
tag.date = tag.date || (new Date()).toISOString();

if (tag.id) {
// tagObjects.push(tag);
await DatabaseServer.updateTag(tag);
tagObjects.push(tag);
} else {
await DatabaseServer.createTag(tag);
}
}
}

// await new DatabaseServer().updateTags(tagObjects)
await new DatabaseServer().updateTags(tagObjects)
}
} else {
throw new Error('Invalid target');
Expand All @@ -529,15 +523,15 @@ export async function tagsAPI(logger: PinoLogger): Promise<void> {
const cache = await DatabaseServer.getTagCache(filter);
if (cache.length) {

// const tagCacheObjects = []
const tagCacheObjects = []

for (const item of cache) {
item.date = date;
await DatabaseServer.updateTagCache(item);
// tagCacheObjects.push(item);

tagCacheObjects.push(item);
}

// await DatabaseServer.updateTagsCache(tagCacheObjects)
await DatabaseServer.updateTagsCache(tagCacheObjects)
} else {
await DatabaseServer.createTagCache({ localTarget, entity, date });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 3 additions & 4 deletions guardian-service/src/policy-engine/policy-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -769,11 +769,10 @@ export class PolicyEngine extends NatsService {
replaceAllEntities(model.config, ['tokenId'], oldId, newToken.tokenId);
replaceAllVariables(model.config, 'Token', oldId, newToken.tokenId);

model = await DatabaseServer.updatePolicy(model);
// policyObjects.push(model);
policyObjects.push(model);
}

// await DatabaseServer.savePolicies(policyObjects);
await DatabaseServer.savePolicies(policyObjects);

const tokenMessage = new TokenMessage(MessageAction.UseToken);
tokenMessage.setDocument(_token);
Expand Down
7 changes: 3 additions & 4 deletions policy-service/src/policy-engine/blocks/tag-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export class TagsManagerBlock {
}
}

// const tagObjects = []
const tagObjects = []

for (const item of map.values()) {
if (item.message) {
Expand All @@ -390,15 +390,14 @@ export class TagsManagerBlock {
tag.date = tag.date || (new Date()).toISOString();

if (tag.id) {
await ref.databaseServer.updateTag(tag);
// tagObjects.push(tag);
tagObjects.push(tag);
} else {
await ref.databaseServer.createTag(tag);
}
}
}

// await ref.databaseServer.updateTags(tagObjects)
await ref.databaseServer.updateTags(tagObjects)
}

}

0 comments on commit 3a53696

Please sign in to comment.