diff --git a/app/lib/use_case/list_location_group.dart b/app/lib/use_case/list_location_group.dart index 48027d07..f424aa50 100644 --- a/app/lib/use_case/list_location_group.dart +++ b/app/lib/use_case/list_location_group.dart @@ -8,19 +8,19 @@ import 'package:nc_photos/location_util.dart' as location_util; class LocationGroup { const LocationGroup( - this.place, this.countryCode, this.latest, this.latestFileId); + this.place, this.countryCode, this.count, this.latestFileId); @override toString() => "$runtimeType {" "place: $place, " "countryCode: $countryCode, " - "latest: $latest, " + "count: $count, " "latestFileId: $latestFileId, " "}"; final String place; final String countryCode; - final DateTime latest; + final int count; final int latestFileId; } @@ -60,14 +60,15 @@ class ListLocationGroup { final countryCodeResult = []; for (final r in account.roots) { final latest = db.accountFiles.bestDateTime.max(); - final nameQ = - _buildQuery(db, dbAccount, r, latest, db.imageLocations.name); + final count = db.imageLocations.rowId.count(); + final nameQ = _buildQuery( + db, dbAccount, r, latest, count, db.imageLocations.name); try { nameResult.addAll(await nameQ .map((r) => LocationGroup( r.read(db.imageLocations.name)!, r.read(db.imageLocations.countryCode)!, - r.read(latest), + r.read(count), r.read(db.files.fileId)!, )) .get()); @@ -75,14 +76,14 @@ class ListLocationGroup { _log.shout("[call] Failed while query name group", e, stackTrace); } - final admin1Q = - _buildQuery(db, dbAccount, r, latest, db.imageLocations.admin1); + final admin1Q = _buildQuery( + db, dbAccount, r, latest, count, db.imageLocations.admin1); try { admin1Result.addAll(await admin1Q .map((r) => LocationGroup( r.read(db.imageLocations.admin1)!, r.read(db.imageLocations.countryCode)!, - r.read(latest), + r.read(count), r.read(db.files.fileId)!, )) .get()); @@ -90,14 +91,14 @@ class ListLocationGroup { _log.shout("[call] Failed while query admin1 group", e, stackTrace); } - final admin2Q = - _buildQuery(db, dbAccount, r, latest, db.imageLocations.admin2); + final admin2Q = _buildQuery( + db, dbAccount, r, latest, count, db.imageLocations.admin2); try { admin2Result.addAll(await admin2Q .map((r) => LocationGroup( r.read(db.imageLocations.admin2)!, r.read(db.imageLocations.countryCode)!, - r.read(latest), + r.read(count), r.read(db.files.fileId)!, )) .get()); @@ -106,12 +107,12 @@ class ListLocationGroup { } final countryCodeQ = _buildQuery( - db, dbAccount, r, latest, db.imageLocations.countryCode); + db, dbAccount, r, latest, count, db.imageLocations.countryCode); try { countryCodeResult.addAll(await countryCodeQ.map((r) { final cc = r.read(db.imageLocations.countryCode)!; return LocationGroup(location_util.alpha2CodeToName(cc) ?? cc, cc, - r.read(latest), r.read(db.files.fileId)!); + r.read(count), r.read(db.files.fileId)!); }).get()); } catch (e, stackTrace) { _log.shout( @@ -131,6 +132,7 @@ class ListLocationGroup { sql.Account dbAccount, String dir, sql.Expression latest, + sql.Expression count, sql.GeneratedColumn groupColumn, ) { final query = db.selectOnly(db.imageLocations).join([ @@ -142,7 +144,7 @@ class ListLocationGroup { ]); if (identical(groupColumn, db.imageLocations.countryCode)) { query - ..addColumns([db.imageLocations.countryCode, latest, db.files.fileId]) + ..addColumns([db.imageLocations.countryCode, count, db.files.fileId]) ..groupBy([db.imageLocations.countryCode], having: db.accountFiles.bestDateTime.equalsExp(latest)); } else { @@ -150,7 +152,7 @@ class ListLocationGroup { ..addColumns([ groupColumn, db.imageLocations.countryCode, - latest, + count, db.files.fileId ]) ..groupBy([groupColumn, db.imageLocations.countryCode], diff --git a/app/lib/widget/places_browser.dart b/app/lib/widget/places_browser.dart index 9e422cdb..ea609df0 100644 --- a/app/lib/widget/places_browser.dart +++ b/app/lib/widget/places_browser.dart @@ -191,11 +191,11 @@ class _PlacesBrowserState extends State { } int sorter(LocationGroup a, LocationGroup b) { - final latestCompare = b.latest.compareTo(a.latest); - if (latestCompare == 0) { + final compare = b.count.compareTo(a.count); + if (compare == 0) { return a.place.compareTo(b.place); } else { - return latestCompare; + return compare; } } diff --git a/app/lib/widget/search_landing.dart b/app/lib/widget/search_landing.dart index 0e96e228..2d8671f5 100644 --- a/app/lib/widget/search_landing.dart +++ b/app/lib/widget/search_landing.dart @@ -269,11 +269,11 @@ class _SearchLandingState extends State { void _transformLocations(LocationGroupResult locations) { _locationItems = locations.name .sorted((a, b) { - final latestCompare = b.latest.compareTo(a.latest); - if (latestCompare == 0) { + final compare = b.count.compareTo(a.count); + if (compare == 0) { return a.place.compareTo(b.place); } else { - return latestCompare; + return compare; } }) .map((e) => _LandingLocationItem(