Parcourir la source

Revert "tmp: disable decorating items completely"

This reverts commit bc1c7a8ae1f6216267da8da191ef7490335be2ec.
Karol Sójko il y a 1 an
Parent
commit
0bf7d8beae

+ 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, true)
+    const extension = await this.itemRepository.findByUuidAndUserUuid(extensionId, userUuid)
     if (extension === null || !extension.props.content) {
       throw Error(`Could not find extensions with id ${extensionId}`)
     }

+ 1 - 2
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, true)
+    const item = await this.itemRepository.findByUuidAndUserUuid(event.payload.itemUuid, event.payload.userUuid)
 
     if (item === null) {
       this.logger.warn(`Could not find item with uuid ${event.payload.itemUuid}`)
@@ -33,7 +33,6 @@ export class DuplicateItemSyncedEventHandler implements DomainEventHandlerInterf
     const existingOriginalItem = await this.itemRepository.findByUuidAndUserUuid(
       item.props.duplicateOf.value,
       event.payload.userUuid,
-      true,
     )
 
     if (existingOriginalItem !== null) {

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

@@ -53,14 +53,11 @@ 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',
-        },
-        true,
-      )
+      const items = await this.itemRepository.findAll({
+        uuids: itemUuidBundle,
+        sortBy: 'updated_at_timestamp',
+        sortOrder: 'ASC',
+      })
 
       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, noAssociations: boolean): Promise<Item[]>
+  findAll(query: ItemQuery): 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, noAssociations: boolean): Promise<Item | null>
+  findByUuidAndUserUuid(uuid: string, userUuid: string): 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, true)
+    const item = await this.itemRepository.findByUuidAndUserUuid(dto.itemUuid, dto.userUuid)
 
     if (item === null) {
       return Result.fail(`Could not find item with uuid ${dto.itemUuid}`)

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

@@ -56,14 +56,11 @@ 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',
-        },
-        true,
-      )
+      items = await this.itemRepository.findAll({
+        uuids: itemUuidsToFetch,
+        sortBy: 'updated_at_timestamp',
+        sortOrder: 'ASC',
+      })
     }
     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, true)
+      const existingItem = await this.itemRepository.findByUuid(itemUuid, false)
 
       if (dto.readOnlyAccess) {
         conflicts.push({

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

@@ -126,15 +126,12 @@ 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',
-      },
-      true,
-    )
+    const itemsKeys = await this.itemRepository.findAll({
+      userUuid,
+      contentType: ContentType.TYPES.ItemsKey,
+      sortBy: 'updated_at_timestamp',
+      sortOrder: 'ASC',
+    })
 
     const retrievedItemsIds: Array<string> = retrievedItems.map((item: Item) => item.id.toString())
 

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