diff options
Diffstat (limited to 'iphone/Maps/Core')
-rw-r--r-- | iphone/Maps/Core/Ads/BannersCache.swift | 30 | ||||
-rw-r--r-- | iphone/Maps/Core/Search/MWMSearch.mm | 12 |
2 files changed, 23 insertions, 19 deletions
diff --git a/iphone/Maps/Core/Ads/BannersCache.swift b/iphone/Maps/Core/Ads/BannersCache.swift index 14fcecb9d1..de12ca0fec 100644 --- a/iphone/Maps/Core/Ads/BannersCache.swift +++ b/iphone/Maps/Core/Ads/BannersCache.swift @@ -22,29 +22,28 @@ final class BannersCache: NSObject { private func onCompletion(isAsync: Bool) { guard let completion = completion else { return } - var bannerType: BannerType? + var banner: Banner? statesLoop: for loadState in loadStates { switch loadState { - case .notLoaded(_): return + case .notLoaded(let type): + banner = cache[type] + break statesLoop case .loaded(let type): - bannerType = type + banner = cache[type] break statesLoop case .error: continue } } - guard bannerType != nil else { return } - guard let banner = cache[bannerType!] else { - assert(false) - return + if let banner = banner { + Statistics.logEvent(kStatPlacePageBannerShow, withParameters: banner.statisticsDescription) + MRMyTracker.trackEvent(withName: kStatPlacePageBannerShow) + completion(banner, isAsync) + banner.isBannerOnScreen = true + self.completion = nil } - Statistics.logEvent(kStatPlacePageBannerShow, withParameters: banner.statisticsDescription) - MRMyTracker.trackEvent(withName: kStatPlacePageBannerShow) - completion(banner, isAsync) - banner.isBannerOnScreen = true - self.completion = nil } - func get(coreBanners: [CoreBanner], completion: @escaping Completion, cacheOnly: Bool) { + func get(coreBanners: [CoreBanner], cacheOnly: Bool, loadNew: Bool = true, completion: @escaping Completion) { self.completion = completion self.cacheOnly = cacheOnly loadStates = coreBanners.map { coreBanner in @@ -52,10 +51,13 @@ final class BannersCache: NSObject { if let banner = cache[bannerType], (!banner.isPossibleToReload || banner.isNeedToRetain) { return .loaded(bannerType) } else { - get(bannerType: bannerType) + if loadNew { + get(bannerType: bannerType) + } return .notLoaded(bannerType) } } + onCompletion(isAsync: false) } diff --git a/iphone/Maps/Core/Search/MWMSearch.mm b/iphone/Maps/Core/Search/MWMSearch.mm index 69e672e89b..1d6952f9d6 100644 --- a/iphone/Maps/Core/Search/MWMSearch.mm +++ b/iphone/Maps/Core/Search/MWMSearch.mm @@ -101,6 +101,7 @@ using TObservers = NSHashTable<__kindof TObserver>; f.SearchInViewport(m_viewportParams); } } + [self updateItemsIndexWithBannerReload:YES]; [self onSearchCompleted]; } else @@ -108,7 +109,7 @@ using TObservers = NSHashTable<__kindof TObserver>; self->m_everywhereResults = results; self->m_isLocalAdsCustomer = isLocalAdsCustomer; self.suggestionsCount = results.GetSuggestsCount(); - [self updateItemsIndex]; + [self updateItemsIndexWithBannerReload:NO]; [self onSearchResultsUpdated]; } }; @@ -258,7 +259,7 @@ using TObservers = NSHashTable<__kindof TObserver>; auto manager = [MWMSearch manager]; manager->m_everywhereResults.Clear(); manager.suggestionsCount = 0; - [manager updateItemsIndex]; + [manager updateItemsIndexWithBannerReload:YES]; [self reset]; } @@ -298,7 +299,7 @@ using TObservers = NSHashTable<__kindof TObserver>; [manager onSearchCompleted]; } -- (void)updateItemsIndex +- (void)updateItemsIndexWithBannerReload:(BOOL)reloadBanner { auto const resultsCount = self->m_everywhereResults.GetCount(); auto const itemsIndex = [[MWMSearchIndex alloc] initWithSuggestionsCount:self.suggestionsCount @@ -313,14 +314,15 @@ using TObservers = NSHashTable<__kindof TObserver>; __weak auto weakSelf = self; [bannersCache getWithCoreBanners:banner_helpers::MatchPriorityBanners(adsEngine.GetSearchBanners()) + cacheOnly:YES + loadNew:reloadBanner completion:^(id<MWMBanner> ad, BOOL isAsync) { __strong auto self = weakSelf; if (!self) return; NSAssert(isAsync == NO, @"Banner is not from cache!"); [self.banners add:ad]; - } - cacheOnly:YES]; + }]; } } else |