Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/production' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Oct 17, 2024
2 parents 0815011 + d78c406 commit 334886b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/api/entities.v2/contracts/EntitiesDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type MarkAsChangedData = { property: string } | { properties: string[] };
export type MarkAsChangedItems = MarkAsChangedCriteria & MarkAsChangedData;

export interface EntitiesDataSource {
updateEntities_OnlyUpdateAndReindex(entity: Entity): Promise<void>;
updateEntity(entity: Entity): Promise<void>;
updateObsoleteMetadataValues(
id: Entity['_id'],
Expand Down
17 changes: 17 additions & 0 deletions app/api/entities.v2/database/MongoEntitiesDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MongoIdHandler } from 'api/common.v2/database/MongoIdGenerator';
import { MongoResultSet } from 'api/common.v2/database/MongoResultSet';
import { MongoTransactionManager } from 'api/common.v2/database/MongoTransactionManager';
import entities from 'api/entities/entities';
import v1EntitiesModel from 'api/entities/entitiesModel';
import { MongoSettingsDataSource } from 'api/settings.v2/database/MongoSettingsDataSource';
import { MongoTemplatesDataSource } from 'api/templates.v2/database/MongoTemplatesDataSource';
import { Db } from 'mongodb';
Expand All @@ -12,6 +13,7 @@ import { EntitiesDataSource } from '../contracts/EntitiesDataSource';
import { Entity, EntityMetadata, MetadataValue } from '../model/Entity';
import { EntityMappers } from './EntityMapper';
import { EntityDBO, EntityJoinTemplate } from './schemas/EntityTypes';
import { search } from 'api/search';

export class MongoEntitiesDataSource
extends MongoDataSource<EntityDBO>
Expand All @@ -34,6 +36,21 @@ export class MongoEntitiesDataSource
this.settingsDS = settingsDS;
}

// eslint-disable-next-line class-methods-use-this
async updateEntities_OnlyUpdateAndReindex(entity: Entity) {
// This is using V1 model and custom reindex here
// this is a hack and should be changed as soon as we finish AT
const entityToModify = await entities.getById(entity._id);
if (!entityToModify) {
throw new Error(`entity does not exists: ${entity._id}`);
}

entityToModify.title = entity.title;
entityToModify.metadata = entity.metadata as MetadataSchema;
await v1EntitiesModel.save(entityToModify);
await search.indexEntities({ sharedId: entity.sharedId });
}

// eslint-disable-next-line class-methods-use-this
async updateEntity(entity: Entity) {
// This is using V1 so that it gets denormalized to speed up development
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class RequestEntityTranslation {
await Promise.all(
updatedEntities.map(async updatedEntity => {
this.logger.info(`[AT] - Pending translation saved on DB for entity - ${entity._id}`);
await this.entitiesDS.updateEntity(updatedEntity);
await this.entitiesDS.updateEntities_OnlyUpdateAndReindex(updatedEntity);
})
);
}
Expand Down

0 comments on commit 334886b

Please sign in to comment.