Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit 731e66b

Browse files
author
Clément Le Provost
committed
Refactor handling of non-existent local index
We take advantage of the new `LocalIndex.exists()` method to avoid running an offline request when the index does not exist locally (unless we explicitly target it). As a consequence, we no longer need to treat a 404 status code specially in the offline result handler.
1 parent e4c06c2 commit 731e66b

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

algoliasearch/src/offline/java/com/algolia/search/saas/MirroredIndex.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,12 @@ public OnlineOfflineRequest start() {
686686
}
687687
// Otherwise, always launch an online request.
688688
else {
689-
if (requestStrategy == Strategy.ONLINE_ONLY) {
689+
if (requestStrategy == Strategy.ONLINE_ONLY || !getLocalIndex().exists()) {
690690
mayRunOfflineRequest = false;
691691
}
692692
startOnline();
693693
}
694-
if (requestStrategy == Strategy.FALLBACK_ON_TIMEOUT) {
694+
if (requestStrategy == Strategy.FALLBACK_ON_TIMEOUT && mayRunOfflineRequest) {
695695
// Schedule an offline request to start after a certain delay.
696696
startOfflineRunnable = new Runnable() {
697697
@Override
@@ -738,12 +738,6 @@ private void startOffline() {
738738
offlineRequest = startOfflineRequest(new CompletionHandler() {
739739
@Override
740740
public void requestCompleted(JSONObject content, AlgoliaException error) {
741-
// NOTE: If we reach this handler, it means the offline request has not been cancelled.
742-
// WARNING: A 404 error likely indicates that the local mirror has not been synced yet, so absorb it...
743-
// ... unless the online request has already finished, meaning the offline has to return a result.
744-
if (error != null && error.getStatusCode() == 404 && onlineRequest != null && onlineRequest.isFinished()) {
745-
return;
746-
}
747741
if (onlineRequest != null) {
748742
onlineRequest.cancel();
749743
}

0 commit comments

Comments
 (0)