Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit c2ef2562 authored by Likai Ding's avatar Likai Ding Committed by Michael Bestas
Browse files

Gallery: improve timeline loading performance

MediaSet's getTotalMediaItemCount() method involves database queries
which is slow. The call is not needed in time clustering as the items
will be enumerated right after that.

Change-Id: I8eaa68237c923486109935180247188da94f397b
CRs-Fixed: 984190
parent cbe9232d
Loading
Loading
Loading
Loading
+2 −11
Original line number Diff line number Diff line
@@ -98,31 +98,22 @@ public class TimeClustering extends Clustering {

    @Override
    public void run(MediaSet baseSet) {
        final int total = baseSet.getTotalMediaItemCount();
        final SmallItem[] buf = new SmallItem[total];
        final double[] latLng = new double[2];

        final ArrayList<SmallItem> items = new ArrayList<>();
        baseSet.enumerateTotalMediaItems(new MediaSet.ItemConsumer() {
            @Override
            public void consume(int index, MediaItem item) {
                if (index < 0 || index >= total) return;
                SmallItem s = new SmallItem();
                s.path = item.getPath();
                s.dateInMs = item.getDateInMs();
                item.getLatLong(latLng);
                s.lat = latLng[0];
                s.lng = latLng[1];
                buf[index] = s;
                items.add(s);
            }
        });

        ArrayList<SmallItem> items = new ArrayList<SmallItem>(total);
        for (int i = 0; i < total; i++) {
            if (buf[i] != null) {
                items.add(buf[i]);
            }
        }

        Collections.sort(items, sDateComparator);

        int n = items.size();