Skip to content

Instantly share code, notes, and snippets.

@ericntd
Created April 4, 2023 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericntd/cbf479b70a0b3bfb643455667381a865 to your computer and use it in GitHub Desktop.
Save ericntd/cbf479b70a0b3bfb643455667381a865 to your computer and use it in GitHub Desktop.
App start scope 3 - ManagerSync
private void startSyncRunnable(QueuedSync queuedSync) {
    //...

    featureFlagRepository.refresh(true)
            .subscribe(() -> {
              if (featureFlagRepository.isEnabled(FeatureConstants.FASTER_APP_START)) {
                long startTime = System.currentTimeMillis();
                List<Completable> completableList = new ArrayList<>();
                completableList.add(priceRepository.refresh());
                completableList.add(refreshMyProfileUseCase.invoke().ignoreElement());
                completableList.add(refreshDiscoverResources().ignoreElement()); // <-- Remove this for Lazy Discover
                completableList.add(refreshLikesYouMatchUseCase.invoke()); // <-- Remove this for Lazy Likes You
                completableList.add(refreshSuggestedLimits()); // <-- Remove this for Lazy Suggested & Chats
                completableList.add(refreshBagels().ignoreElement());
                completableList.addAll(fetchQuestionsAndAnswersAsync());
                Completable[] completables = completableList.toArray(new Completable[]{});
                Completable.mergeArray(completables)
                        .subscribe(() -> {
                          //...
                          
                          /*
                          No need to wait for bagel & couple download to finish
                          - Suggested is already observing the local DB and reacting to changes
                          - ChatListFragment is already observing the local DB and reacting to changes?
                           */
                          refreshBagels().subscribe(
                            () -> Logger.d(TAG, "finished downloading bagels"),
                            throwable -> Logger.e(TAG, "problem downloading bagels", throwable)
                          );

                          handleSyncSuccess(queuedSync.callBack, null, new SuccessStatus("Data Sync Completed"));
                        }, throwable -> {
                          Logger.e(TAG, "problem getting Suggested, Likes You, Discover or Chat resources", throwable);
                          handleSyncError(queuedSync.callBack, new CmbErrorCode(throwable.getMessage()));
                        });
              } else {
                // legacy branch
              }
            });
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment