1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-03 05:34:51 +00:00

Chunk by range

This commit is contained in:
M66B 2024-10-24 20:35:42 +02:00
parent 20d3449d32
commit 5e74805997
2 changed files with 18 additions and 1 deletions

View file

@ -4172,7 +4172,22 @@ class Core {
if (chunk_size < 200 &&
(account.isGmail() || account.isOutlook()))
chunk_size = 200;
List<List<Pair<Long, Long>>> chunks = Helper.chunkList(ranges, chunk_size);
List<List<Pair<Long, Long>>> chunks = new ArrayList<>();
int s = 0;
List<Pair<Long, Long>> r = new ArrayList<>();
for (Pair<Long, Long> range : ranges) {
long n = range.second - range.first + 1;
if (s + n > range_size) {
chunks.addAll(Helper.chunkList(r, chunk_size));
s = 0;
r.clear();
}
s += n;
r.add(range);
}
chunks.addAll(Helper.chunkList(r, chunk_size));
Log.i(folder.name + " executing uid fetch count=" + uids.size() +
" ranges=" + ranges.size() + " chunks=" + chunks.size() +

View file

@ -3789,6 +3789,8 @@ public class Helper {
}
static <T> List<List<T>> chunkList(List<T> list, int size) {
if (list == null || list.isEmpty())
return new ArrayList<>();
List<List<T>> result = new ArrayList<>(list.size() / size);
for (int i = 0; i < list.size(); i += size)
result.add(list.subList(i, i + size < list.size() ? i + size : list.size()));