Просмотр исходного кода

tmp: disable decorating items completely

Karol Sójko 1 год назад
Родитель
Сommit
bc1c7a8ae1

+ 1 - 1
packages/syncing-server/src/Domain/Extension/ExtensionsHttpService.ts

@@ -139,7 +139,7 @@ export class ExtensionsHttpService implements ExtensionsHttpServiceInterface {
     userUuid: string,
     email: string,
   ): Promise<DomainEventInterface> {
-    const extension = await this.itemRepository.findByUuidAndUserUuid(extensionId, userUuid)
+    const extension = await this.itemRepository.findByUuidAndUserUuid(extensionId, userUuid, true)
     if (extension === null || !extension.props.content) {
       throw Error(`Could not find extensions with id ${extensionId}`)
     }

+ 2 - 1
packages/syncing-server/src/Domain/Handler/DuplicateItemSyncedEventHandler.ts

@@ -16,7 +16,7 @@ export class DuplicateItemSyncedEventHandler implements DomainEventHandlerInterf
   ) {}
 
   async handle(event: DuplicateItemSyncedEvent): Promise<void> {
-    const item = await this.itemRepository.findByUuidAndUserUuid(event.payload.itemUuid, event.payload.userUuid)
+    const item = await this.itemRepository.findByUuidAndUserUuid(event.payload.itemUuid, event.payload.userUuid, true)
 
     if (item === null) {
       this.logger.warn(`Could not find item with uuid ${event.payload.itemUuid}`)
@@ -33,6 +33,7 @@ export class DuplicateItemSyncedEventHandler implements DomainEventHandlerInterf
     const existingOriginalItem = await this.itemRepository.findByUuidAndUserUuid(
       item.props.duplicateOf.value,
       event.payload.userUuid,
+      true,
     )
 
     if (existingOriginalItem !== null) {

+ 8 - 5
packages/syncing-server/src/Domain/Handler/EmailBackupRequestedEventHandler.ts

@@ -53,11 +53,14 @@ export class EmailBackupRequestedEventHandler implements DomainEventHandlerInter
 
     const backupFileNames: string[] = []
     for (const itemUuidBundle of itemUuidBundles) {
-      const items = await this.itemRepository.findAll({
-        uuids: itemUuidBundle,
-        sortBy: 'updated_at_timestamp',
-        sortOrder: 'ASC',
-      })
+      const items = await this.itemRepository.findAll(
+        {
+          uuids: itemUuidBundle,
+          sortBy: 'updated_at_timestamp',
+          sortOrder: 'ASC',
+        },
+        true,
+      )
 
       const bundleBackupFileNames = await this.itemBackupService.backup(
         items,

+ 2 - 2
packages/syncing-server/src/Domain/Item/ItemRepositoryInterface.ts

@@ -7,7 +7,7 @@ import { ExtendedIntegrityPayload } from './ExtendedIntegrityPayload'
 
 export interface ItemRepositoryInterface {
   deleteByUserUuid(userUuid: string): Promise<void>
-  findAll(query: ItemQuery): Promise<Item[]>
+  findAll(query: ItemQuery, noAssociations: boolean): Promise<Item[]>
   findAllRaw<T>(query: ItemQuery): Promise<T[]>
   streamAll(query: ItemQuery): Promise<ReadStream>
   countAll(query: ItemQuery): Promise<number>
@@ -16,7 +16,7 @@ export interface ItemRepositoryInterface {
   ): Promise<Array<{ uuid: string; contentSize: number | null }>>
   findDatesForComputingIntegrityHash(userUuid: string): Promise<Array<{ updated_at_timestamp: number }>>
   findItemsForComputingIntegrityPayloads(userUuid: string): Promise<ExtendedIntegrityPayload[]>
-  findByUuidAndUserUuid(uuid: string, userUuid: string): Promise<Item | null>
+  findByUuidAndUserUuid(uuid: string, userUuid: string, noAssociations: boolean): Promise<Item | null>
   findByUuid(uuid: Uuid, noAssociations: boolean): Promise<Item | null>
   remove(item: Item): Promise<void>
   save(item: Item): Promise<void>

+ 1 - 1
packages/syncing-server/src/Domain/UseCase/Syncing/GetItem/GetItem.ts

@@ -8,7 +8,7 @@ export class GetItem implements UseCaseInterface<Item> {
   constructor(private itemRepository: ItemRepositoryInterface) {}
 
   async execute(dto: GetItemDTO): Promise<Result<Item>> {
-    const item = await this.itemRepository.findByUuidAndUserUuid(dto.itemUuid, dto.userUuid)
+    const item = await this.itemRepository.findByUuidAndUserUuid(dto.itemUuid, dto.userUuid, true)
 
     if (item === null) {
       return Result.fail(`Could not find item with uuid ${dto.itemUuid}`)

+ 8 - 5
packages/syncing-server/src/Domain/UseCase/Syncing/GetItems/GetItems.ts

@@ -56,11 +56,14 @@ export class GetItems implements UseCaseInterface<GetItemsResult> {
     )
     let items: Array<Item> = []
     if (itemUuidsToFetch.length > 0) {
-      items = await this.itemRepository.findAll({
-        uuids: itemUuidsToFetch,
-        sortBy: 'updated_at_timestamp',
-        sortOrder: 'ASC',
-      })
+      items = await this.itemRepository.findAll(
+        {
+          uuids: itemUuidsToFetch,
+          sortBy: 'updated_at_timestamp',
+          sortOrder: 'ASC',
+        },
+        true,
+      )
     }
     const totalItemsCount = await this.itemRepository.countAll(itemQuery)
 

+ 1 - 1
packages/syncing-server/src/Domain/UseCase/Syncing/SaveItems/SaveItems.ts

@@ -42,7 +42,7 @@ export class SaveItems implements UseCaseInterface<SaveItemsResult> {
       }
       const itemUuid = itemUuidOrError.getValue()
 
-      const existingItem = await this.itemRepository.findByUuid(itemUuid, false)
+      const existingItem = await this.itemRepository.findByUuid(itemUuid, true)
 
       if (dto.readOnlyAccess) {
         conflicts.push({

+ 9 - 6
packages/syncing-server/src/Domain/UseCase/Syncing/SyncItems/SyncItems.ts

@@ -126,12 +126,15 @@ export class SyncItems implements UseCaseInterface<SyncItemsResponse> {
   }
 
   private async frontLoadKeysItemsToTop(userUuid: string, retrievedItems: Array<Item>): Promise<Array<Item>> {
-    const itemsKeys = await this.itemRepository.findAll({
-      userUuid,
-      contentType: ContentType.TYPES.ItemsKey,
-      sortBy: 'updated_at_timestamp',
-      sortOrder: 'ASC',
-    })
+    const itemsKeys = await this.itemRepository.findAll(
+      {
+        userUuid,
+        contentType: ContentType.TYPES.ItemsKey,
+        sortBy: 'updated_at_timestamp',
+        sortOrder: 'ASC',
+      },
+      true,
+    )
 
     const retrievedItemsIds: Array<string> = retrievedItems.map((item: Item) => item.id.toString())
 

+ 10 - 2
packages/syncing-server/src/Infra/TypeORM/TypeORMItemRepository.ts

@@ -130,7 +130,7 @@ export class TypeORMItemRepository implements ItemRepositoryInterface {
     return items.sort((itemA, itemB) => itemB.updated_at_timestamp - itemA.updated_at_timestamp)
   }
 
-  async findByUuidAndUserUuid(uuid: string, userUuid: string): Promise<Item | null> {
+  async findByUuidAndUserUuid(uuid: string, userUuid: string, noAssociations: boolean): Promise<Item | null> {
     const persistence = await this.ormRepository
       .createQueryBuilder('item')
       .where('item.uuid = :uuid AND item.user_uuid = :userUuid', {
@@ -146,6 +146,10 @@ export class TypeORMItemRepository implements ItemRepositoryInterface {
     try {
       const item = this.mapper.toDomain(persistence)
 
+      if (noAssociations) {
+        return item
+      }
+
       await this.decorateItemWithAssociations(item)
 
       return item
@@ -156,7 +160,7 @@ export class TypeORMItemRepository implements ItemRepositoryInterface {
     }
   }
 
-  async findAll(query: ItemQuery): Promise<Item[]> {
+  async findAll(query: ItemQuery, noAssociations: boolean): Promise<Item[]> {
     const persistence = await this.createFindAllQueryBuilder(query).getMany()
 
     const domainItems: Item[] = []
@@ -168,6 +172,10 @@ export class TypeORMItemRepository implements ItemRepositoryInterface {
       }
     }
 
+    if (noAssociations) {
+      return domainItems
+    }
+
     await Promise.all(domainItems.map((item) => this.decorateItemWithAssociations(item)))
 
     return domainItems