Skip to content

Commit

Permalink
Merge pull request osmandapp#19772 from osmandapp/sonora-patch-2
Browse files Browse the repository at this point in the history
Bulk load GPX cache
  • Loading branch information
Chumva authored May 9, 2024
2 parents 1529e20 + 256b594 commit 638f94a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions OsmAnd/src/net/osmand/plus/track/helpers/GpxDbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;

public class GpxDbHelper implements GpxDbReaderCallback {
private static final Log LOG = PlatformUtil.getLog(GpxDbHelper.class);
Expand Down Expand Up @@ -59,25 +60,19 @@ public void loadItems() {

public void loadGpxItems() {
long start = System.currentTimeMillis();
long batchTime = System.currentTimeMillis();
List<GpxDataItem> items = getItems();

int counter = 0;
for (GpxDataItem item : items) {
Map<File, Boolean> fileExistenceMap = items.stream().collect(Collectors.toMap(GpxDataItem::getFile, item -> item.getFile().exists()));

items.forEach(item -> {
File file = item.getFile();
if (file.exists()) {
putToCache(item);
if (Boolean.TRUE.equals(fileExistenceMap.get(file))) {
dataItems.put(file, item);
} else {
remove(file);
}
counter++;
if (counter % 100 == 0) {
long endTime = System.currentTimeMillis();
LOG.info("Loading tracks batch. took " + (endTime - batchTime) + "ms");
batchTime = endTime;
}
}
LOG.info("Time to loadGpxItems " + (System.currentTimeMillis() - start) + " ms items count " + items.size());
});
LOG.info("Time to loadGpxItems " + (System.currentTimeMillis() - start) + " ms, " + items.size() + " items");
}

public void loadGpxDirItems() {
Expand Down Expand Up @@ -335,4 +330,4 @@ public void onReadingFinished(boolean cancelled) {
readerTask = null;
}
}
}
}

0 comments on commit 638f94a

Please sign in to comment.