Refactoring

pull/194/merge
M66B 3 years ago
parent c1a6373133
commit f967292a2f

@ -76,6 +76,7 @@ public class ViewModelMessages extends ViewModel {
private static final int REMOTE_PAGE_SIZE = 10; private static final int REMOTE_PAGE_SIZE = 10;
private static final int SEARCH_PAGE_SIZE = 10; private static final int SEARCH_PAGE_SIZE = 10;
private static final int MAX_CACHED_ITEMS = LOCAL_PAGE_SIZE * 50; private static final int MAX_CACHED_ITEMS = LOCAL_PAGE_SIZE * 50;
private static final int CHUNK_SIZE = 100;
Model getModel( Model getModel(
final Context context, final LifecycleOwner owner, final Context context, final LifecycleOwner owner,
@ -360,16 +361,16 @@ public class ViewModelMessages extends ViewModel {
return getPair(plist, ds, count, from + j); return getPair(plist, ds, count, from + j);
} }
for (int i = 0; i < count; i += 100) { for (int i = 0; i < count; i += CHUNK_SIZE) {
Log.i("Observe previous/next load" + Log.i("Observe previous/next load" +
" range=" + i + "/#" + count); " range=" + i + "/#" + count);
List<TupleMessageEx> messages = ds.loadRange(i, Math.min(100, count - i)); List<TupleMessageEx> messages = ds.loadRange(i, Math.min(CHUNK_SIZE, count - i));
for (int j = 0; j < messages.size(); j++) for (int j = 0; j < messages.size(); j++)
if (messages.get(j).id == id) if (messages.get(j).id == id)
return getPair(plist, ds, count, i + j); return getPair(plist, ds, count, i + j);
if (lpos < 0 && i == 500 && count > 1000) if (lpos < 0 && i == CHUNK_SIZE * 2 && count > CHUNK_SIZE * 4)
i = count - 500; i = count - CHUNK_SIZE * 2;
} }
Log.i("Observe previous/next message not found" + Log.i("Observe previous/next message not found" +

Loading…
Cancel
Save