From 329339dc0317d9540055059cc385bcfad047d598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20So=C3=B3s?= Date: Thu, 9 Nov 2023 10:39:08 +0100 Subject: [PATCH] Update all popularity when updating the search snapshot. (#7169) --- app/lib/search/backend.dart | 8 ++++++++ app/lib/search/search_service.dart | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/lib/search/backend.dart b/app/lib/search/backend.dart index 41111d610b..af6def178d 100644 --- a/app/lib/search/backend.dart +++ b/app/lib/search/backend.dart @@ -197,7 +197,15 @@ class SearchBackend { futures.clear(); if (claim.valid && lastUploadedSnapshotTimestamp != snapshot.updated) { + // Updates the normalized like score across all the packages. snapshot.updateLikeScores(); + + // Updates all popularity values to the currently cached one, otherwise + // only updated package would have been on their new values. + for (final d in snapshot.documents!.values) { + d.popularityScore = popularityStorage.lookup(d.package); + } + await _snapshotStorage.uploadDataAsJsonMap(snapshot.toJson()); lastUploadedSnapshotTimestamp = snapshot.updated!; } diff --git a/app/lib/search/search_service.dart b/app/lib/search/search_service.dart index 43154ec52b..9a2955294f 100644 --- a/app/lib/search/search_service.dart +++ b/app/lib/search/search_service.dart @@ -78,7 +78,7 @@ class PackageDocument { double? likeScore; /// The normalized score between [0.0-1.0] (1.0 being the most popular package). - final double? popularityScore; + double? popularityScore; final int grantedPoints; final int maxPoints;