Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
revert api timeout and increase for search
Browse files Browse the repository at this point in the history
closes #881
  • Loading branch information
sk22 committed Oct 20, 2023
1 parent 183fb0e commit 9de8335
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public class MastodonAPIController{
.registerTypeAdapter(Status.class, new Status.StatusDeserializer())
.create();
private static WorkerThread thread=new WorkerThread("MastodonAPIController");
private static OkHttpClient httpClient=new OkHttpClient.Builder()
.readTimeout(5, TimeUnit.MINUTES)
.build();
private static OkHttpClient httpClient=new OkHttpClient.Builder().build();

private AccountSession session;
private static List<String> badDomains = new ArrayList<>();
Expand Down Expand Up @@ -113,13 +111,13 @@ else if(req.token!=null)
}

Request hreq=builder.build();
Call call=httpClient.newCall(hreq);
OkHttpClient client=req.timeout>0
? httpClient.newBuilder().readTimeout(req.timeout, TimeUnit.MILLISECONDS).build()
: httpClient;
Call call=client.newCall(hreq);
synchronized(req){
req.okhttpCall=call;
}
if(req.timeout>0){
call.timeout().timeout(req.timeout, TimeUnit.MILLISECONDS);
}

if(BuildConfig.DEBUG)
Log.d(TAG, "["+(session==null ? "no-auth" : session.getID())+"] Sending request: "+hreq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ protected void addHeader(String key, String value){
headers.put(key, value);
}

protected void setTimeout(long timeout){
public MastodonAPIRequest<T> setTimeout(long timeout){
this.timeout=timeout;
return this;
}

protected String getPathPrefix(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import me.grishka.appkit.Nav;
import me.grishka.appkit.api.Callback;
import me.grishka.appkit.api.ErrorResponse;
import me.grishka.appkit.api.SimpleCallback;
import me.grishka.appkit.utils.V;

public class SearchFragment extends BaseStatusListFragment<SearchResult>{
Expand Down Expand Up @@ -142,7 +143,7 @@ else if(!data.isEmpty())
}*/
int offset=_offset;
currentRequest=new GetSearchResults(currentQuery, type, type==null, maxID, offset, type==null ? 0 : count)
.setCallback(new Callback<>(){
.setCallback(new SimpleCallback<>(this){
@Override
public void onSuccess(SearchResults result){
ArrayList<SearchResult> results=new ArrayList<>();
Expand All @@ -165,16 +166,8 @@ public void onSuccess(SearchResults result){
unfilteredResults=results;
onDataLoaded(filterSearchResults(results), type!=null && !results.isEmpty());
}

@Override
public void onError(ErrorResponse error){
currentRequest=null;
Activity a=getActivity();
if(a==null)
return;
error.showToast(a);
}
})
.setTimeout(180000) // 3 minutes (searches can take a long time)
.exec(accountID);
}

Expand Down

0 comments on commit 9de8335

Please sign in to comment.