Skip to content

Commit

Permalink
SAO-1806: Fix hangs upon node updates for big folders.
Browse files Browse the repository at this point in the history
  • Loading branch information
mega-mvc committed Jul 18, 2024
1 parent 35fa3b2 commit 615bd6b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
14 changes: 3 additions & 11 deletions MEGAUnitTests/Home/Search/HomeSearchResultsProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ fileprivate extension Date {
class HomeSearchResultsProviderTests: XCTestCase {

class Harness {
static let parentNodeHandle: HandleEntity = 999
let filesSearchUseCase: MockFilesSearchUseCase
let nodeDetails: MockNodeDetailUseCase
let nodeDataUseCase: MockNodeDataUseCase
let mediaUseCase: MockMediaUseCase
let nodesUpdateListenerRepo: MockSDKNodesUpdateListenerRepository
let nodeUpdateRepository: MockNodeUpdateRepository
let downloadTransfersListener: MockDownloadTransfersListener
let contentConsumptionUserAttributeUseCase: MockContentConsumptionUserAttributeUseCase
let sut: HomeSearchResultsProvider
Expand Down Expand Up @@ -100,8 +100,6 @@ class HomeSearchResultsProviderTests: XCTestCase {
mediaUseCase = MockMediaUseCase()

nodesUpdateListenerRepo = MockSDKNodesUpdateListenerRepository.newRepo

nodeUpdateRepository = MockNodeUpdateRepository()

downloadTransfersListener = MockDownloadTransfersListener()

Expand All @@ -110,15 +108,14 @@ class HomeSearchResultsProviderTests: XCTestCase {
)

sut = HomeSearchResultsProvider(
parentNodeProvider: { NodeEntity(handle: 123) },
parentNodeProvider: { NodeEntity(handle: Harness.parentNodeHandle) },
filesSearchUseCase: filesSearchUseCase,
nodeDetailUseCase: nodeDetails,
nodeUseCase: nodeDataUseCase,
mediaUseCase: mediaUseCase,
nodesUpdateListenerRepo: nodesUpdateListenerRepo,
downloadTransferListener: downloadTransfersListener,
nodeIconUsecase: MockNodeIconUsecase(stubbedIconData: Data()),
nodeUpdateRepository: nodeUpdateRepository,
contentConsumptionUserAttributeUseCase: contentConsumptionUserAttributeUseCase,
allChips: SearchChipEntity.allChips(
areChipsGroupEnabled: true,
Expand Down Expand Up @@ -678,9 +675,6 @@ class HomeSearchResultsProviderTests: XCTestCase {
nodeUpdatesSignals.append($0)
})

harness.nodeUpdateRepository.shouldProcessOnNodesUpdateValue = false
_ = await harness.sut.search(queryRequest: .initial, lastItemIndex: nil)

// when
harness.nodesUpdateListenerRepo.onNodesUpdateHandler?(nodes)

Expand All @@ -702,8 +696,6 @@ class HomeSearchResultsProviderTests: XCTestCase {
expectation.fulfill()
}
})

harness.nodeUpdateRepository.shouldProcessOnNodesUpdateValue = true
_ = await harness.sut.search(queryRequest: .initial, lastItemIndex: nil)

let task = Task {
Expand All @@ -712,7 +704,7 @@ class HomeSearchResultsProviderTests: XCTestCase {

// when

harness.nodesUpdateListenerRepo.onNodesUpdateHandler?(nodes) // Trigger .generic signal
harness.nodesUpdateListenerRepo.onNodesUpdateHandler?([.init(parentHandle: Harness.parentNodeHandle)]) // Trigger .generic signal
harness.downloadTransfersListener.simulateDownloadedNode(nodes[1]) // Trigger .specific signal

await fulfillment(of: [expectation], timeout: 1.0)
Expand Down
1 change: 0 additions & 1 deletion iMEGA/Home/Scenes/HomeScreenFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ final class HomeScreenFactory: NSObject {
nodesUpdateListenerRepo: makeNodesUpdateListenerRepo(),
downloadTransferListener: makeDownloadTransfersListener(),
nodeIconUsecase: makeNodeIconUsecase(),
nodeUpdateRepository: NodeUpdateRepository.newRepo,
contentConsumptionUserAttributeUseCase: ContentConsumptionUserAttributeUseCase(repo: UserAttributeRepository.newRepo),
allChips: Self.allChips(areChipsGroupEnabled: featureFlagProvider.isFeatureFlagEnabled(for: .chipsGroups)),
sdk: sdk,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ final class HomeSearchResultsProvider: SearchResultsProviding {
// root node can be nil in case when we start app in offline
private let parentNodeProvider: () -> NodeEntity?
private let mapper: SearchResultMapper
private let nodeUpdateRepository: any NodeUpdateRepositoryProtocol
private let notificationCenter: NotificationCenter
private var subscriptions = Set<AnyCancellable>()

Expand All @@ -55,7 +54,6 @@ final class HomeSearchResultsProvider: SearchResultsProviding {
nodesUpdateListenerRepo: some NodesUpdateListenerProtocol,
downloadTransferListener: some DownloadTransfersListening,
nodeIconUsecase: some NodeIconUsecaseProtocol,
nodeUpdateRepository: some NodeUpdateRepositoryProtocol,
contentConsumptionUserAttributeUseCase: some ContentConsumptionUserAttributeUseCaseProtocol,
notificationCenter: NotificationCenter = .default,
allChips: [SearchChipEntity],
Expand All @@ -71,7 +69,6 @@ final class HomeSearchResultsProvider: SearchResultsProviding {
self.mediaUseCase = mediaUseCase
self.nodesUpdateListenerRepo = nodesUpdateListenerRepo
self.downloadTransferListener = downloadTransferListener
self.nodeUpdateRepository = nodeUpdateRepository
self.contentConsumptionUserAttributeUseCase = contentConsumptionUserAttributeUseCase
self.notificationCenter = notificationCenter
self.availableChips = allChips
Expand Down Expand Up @@ -282,15 +279,16 @@ final class HomeSearchResultsProvider: SearchResultsProviding {
mapper.map(node: node)
}

// Need some improvements node update listening mechanism - [SAO-1821]
private func addNodesUpdateHandler() {
nodesUpdateListenerRepo.onNodesUpdateHandler = { [weak self] updatedNodes in
guard let self,
let parentNode = self.parentNode,
let childNodes = self.nodeList?.toNodeEntities(),
self.nodeUpdateRepository.shouldProcessOnNodesUpdate(parentNode: parentNode, childNodes: childNodes, updatedNodes: updatedNodes) else {
return
guard let self else { return }
Task { [weak self] in
guard let self, let parentNodeHandle = self.parentNode?.handle,
updatedNodes.contains(where: { $0.handle == parentNodeHandle })
|| updatedNodes.contains(where: { $0.parentHandle == parentNodeHandle }) else { return }
self.onSearchResultsUpdated(.generic)
}
self.onSearchResultsUpdated(.generic)
}
}
}
Expand Down

0 comments on commit 615bd6b

Please sign in to comment.