Skip to content

Commit

Permalink
Remove popularity from the UI, finalize download counts experiment. (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 6, 2025
1 parent cb13f31 commit 9592cc1
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 91 deletions.
1 change: 0 additions & 1 deletion app/lib/frontend/handlers/custom_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ Future<VersionScore> packageVersionScoreHandler(
maxPoints: card.maxPubPoints,
likeCount: pkg.likes,
downloadCount30Days: card.thirtyDaysDownloadCounts,
popularityScore: card.popularityScore,
tags: tags.toList(),
lastUpdated: updated,
);
Expand Down
2 changes: 0 additions & 2 deletions app/lib/frontend/handlers/experimental.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ typedef PublicFlag = ({String name, String description});

const _publicFlags = <PublicFlag>{
(name: 'dark', description: 'Dark mode'),
(name: 'download-counts', description: 'Download count metrics'),
(name: 'search-completion', description: 'Completions for the search bar'),
(name: 'search-topics', description: 'Show matching topics when searching'),
(
Expand Down Expand Up @@ -101,7 +100,6 @@ class ExperimentalFlags {

bool get showDownloadCountsVersionChart =>
isEnabled('download-counts-version-chart');
bool get showDownloadCounts => true;

String encodedAsCookie() => _enabled.join(':');

Expand Down
12 changes: 3 additions & 9 deletions app/lib/frontend/templates/_consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:_pub_shared/search/tags.dart';
import 'package:pub_dev/frontend/request_context.dart';

import '../dom/dom.dart' as d;

Expand Down Expand Up @@ -116,19 +115,14 @@ final _sortDicts = const <SortDict>[
label: 'most pub points',
tooltip: 'Packages are sorted by pub points.'),
SortDict(
id: 'popularity',
label: 'popularity',
tooltip: 'Packages are sorted by their popularity score.'),
id: 'downloads',
label: 'downloads',
tooltip: 'Packages are sorted by their download counts.'),
];

List<SortDict> getSortDicts(bool isSearch) {
final removeId = isSearch ? 'listing_relevance' : 'search_relevance';
return <SortDict>[
..._sortDicts.where((d) => d.id != removeId),
if (requestContext.experimentalFlags.showDownloadCounts)
SortDict(
id: 'downloads',
label: 'downloads',
tooltip: 'Packages are sorted by their download counts.'),
];
}
4 changes: 1 addition & 3 deletions app/lib/frontend/templates/views/pkg/info_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:_pub_shared/format/encoding.dart';
import 'package:pana/pana.dart';
import 'package:pub_dev/frontend/request_context.dart';
import 'package:pub_dev/service/download_counts/download_counts.dart';
import 'package:pubspec_parse/pubspec_parse.dart' as pubspek;

Expand Down Expand Up @@ -83,8 +82,7 @@ d.Node packageInfoBoxNode({
collectionsIcon(),
]),
_publisher(package.publisherId),
if (data.weeklyDownloadCounts != null &&
requestContext.experimentalFlags.showDownloadCounts)
if (data.weeklyDownloadCounts != null)
_downloadsChart(data.weeklyDownloadCounts!),
_metadata(
description: version.pubspec!.description,
Expand Down
40 changes: 14 additions & 26 deletions app/lib/frontend/templates/views/pkg/labeled_scores.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:_pub_shared/format/number_format.dart';
import 'package:pub_dev/frontend/request_context.dart';
import 'package:pub_dev/shared/popularity_storage.dart';

import '../../../dom/dom.dart' as d;

Expand All @@ -31,30 +29,20 @@ d.Node labeledScoresNode({
classes: ['packages-score', 'packages-score-health'],
child: _labeledScore('points', grantedPubPoints?.toString(), sign: ''),
),
requestContext.experimentalFlags.showDownloadCounts
? d.div(
attributes: {
'title':
'Number of downloads of this package during the past 30 days'
},
classes: ['packages-score', 'packages-score-downloads'],
child: _labeledScore(
'downloads',
thirtyDaysDownloads != null
? '${compactFormat(thirtyDaysDownloads).value}'
'${compactFormat(thirtyDaysDownloads).suffix}'
: null,
sign: '',
),
)
: d.div(
classes: ['packages-score', 'packages-score-popularity'],
child: _labeledScore(
'popularity',
popularityStorage.isInvalid ? null : popularity.toString(),
sign: popularityStorage.isInvalid ? '' : '%',
),
),
d.div(
attributes: {
'title': 'Number of downloads of this package during the past 30 days'
},
classes: ['packages-score', 'packages-score-downloads'],
child: _labeledScore(
'downloads',
thirtyDaysDownloads != null
? '${compactFormat(thirtyDaysDownloads).value}'
'${compactFormat(thirtyDaysDownloads).suffix}'
: null,
sign: '',
),
),
],
);
}
Expand Down
21 changes: 1 addition & 20 deletions app/lib/frontend/templates/views/pkg/score_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import 'dart:convert';
import 'package:_pub_shared/data/download_counts_data.dart';
import 'package:_pub_shared/format/number_format.dart';
import 'package:pana/models.dart';
import 'package:pub_dev/shared/popularity_storage.dart';
import 'package:pub_dev/shared/utils.dart';

import '../../../../scorecard/models.dart' hide ReportStatus;
import '../../../../shared/urls.dart' as urls;
import '../../../dom/dom.dart' as d;
import '../../../request_context.dart';
import '../../../static_files.dart';
import '../../package_misc.dart' show formatScore;

/// Renders the score page content.
d.Node scoreTabNode({
Expand Down Expand Up @@ -45,9 +43,7 @@ d.Node scoreTabNode({
children: [
_likeKeyFigureNode(likeCount),
_pubPointsKeyFigureNode(report, showPending),
requestContext.experimentalFlags.showDownloadCounts
? _downloadCountsKeyFigureNode(card.thirtyDaysDownloadCounts)
: _popularityKeyFigureNode(card.popularityScore),
_downloadCountsKeyFigureNode(card.thirtyDaysDownloadCounts),
],
),
if (showPending)
Expand Down Expand Up @@ -281,21 +277,6 @@ d.Node _likeKeyFigureNode(int? likeCount) {
);
}

d.Node _popularityKeyFigureNode(double? popularity) {
if (popularityStorage.isInvalid) {
return _keyFigureNode(
value: '--',
supplemental: '',
label: 'popularity',
);
}
return _keyFigureNode(
value: formatScore(popularity),
supplemental: '%',
label: 'popularity',
);
}

d.Node _downloadCountsKeyFigureNode(int? downloadCounts) {
if (downloadCounts == null) {
return _keyFigureNode(
Expand Down
5 changes: 1 addition & 4 deletions app/lib/scorecard/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:pub_dev/service/download_counts/backend.dart';
import 'package:pub_dev/task/models.dart';

import '../scorecard/backend.dart';
import '../shared/popularity_storage.dart';
import '../shared/utils.dart' show jsonUtf8Encoder, utf8JsonDecoder;

part 'models.g.dart';
Expand Down Expand Up @@ -72,9 +71,7 @@ class ScoreCardData {

List<String>? get tags => panaReport?.derivedTags;

// TODO: refactor code to use popularityStorage directly.
double get popularityScore => popularityStorage.lookup(packageName!);

// TODO: refactor code to use downloadCountsBackend directly.
int? get thirtyDaysDownloadCounts =>
downloadCountsBackend.lookup30DaysTotalCounts(packageName!);
}
Expand Down
2 changes: 0 additions & 2 deletions app/lib/search/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import 'package:retry/retry.dart';
import '../../publisher/backend.dart';
import '../../service/download_counts/backend.dart';
import '../../service/topics/models.dart';
import '../../shared/popularity_storage.dart';
import '../../shared/redis_cache.dart';
import '../../shared/utils.dart';
import '../package/backend.dart';
Expand Down Expand Up @@ -354,7 +353,6 @@ class SearchBackend {
readme: compactReadme(readmeAsset?.textContent),
downloadCount: downloadCountsBackend.lookup30DaysTotalCounts(pv.package),
likeCount: p.likes,
popularityScore: popularityStorage.lookup(packageName),
grantedPoints: scoreCard.grantedPubPoints,
maxPoints: scoreCard.maxPubPoints,
dependencies: _buildDependencies(pv.pubspec!, scoreCard),
Expand Down
11 changes: 0 additions & 11 deletions app/lib/search/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import 'package:clock/clock.dart';
import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:pub_dev/shared/popularity_storage.dart';

import 'search_service.dart';

Expand Down Expand Up @@ -46,16 +45,6 @@ class SearchSnapshot {
/// The score is normalized into the range of [0.0 - 1.0] using the
/// ordered list of packages by like counts (same like count gets the same score).
documents!.values.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 documents!.values) {
if (popularityStorage.isInvalid) {
d.popularityScore = d.likeScore;
} else {
d.popularityScore = popularityStorage.lookup(d.package);
}
}
}

Map<String, dynamic> toJson() => _$SearchSnapshotToJson(this);
Expand Down
1 change: 0 additions & 1 deletion app/test/frontend/golden/pkg_index_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ <h3 class="search-form-section-header foldable-button">
<button class="sort-control-option" data-value="created">newest package</button>
<button class="sort-control-option" data-value="like">most likes</button>
<button class="sort-control-option" data-value="points">most pub points</button>
<button class="sort-control-option" data-value="popularity">popularity</button>
<button class="sort-control-option" data-value="downloads">downloads</button>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion app/test/frontend/golden/publisher_packages_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ <h1 class="title">example.com</h1>
<button class="sort-control-option" data-value="created">newest package</button>
<button class="sort-control-option" data-value="like">most likes</button>
<button class="sort-control-option" data-value="points">most pub points</button>
<button class="sort-control-option" data-value="popularity">popularity</button>
<button class="sort-control-option" data-value="downloads">downloads</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ <h1 class="title">example.com</h1>
<button class="sort-control-option" data-value="created">newest package</button>
<button class="sort-control-option" data-value="like">most likes</button>
<button class="sort-control-option" data-value="points">most pub points</button>
<button class="sort-control-option" data-value="popularity">popularity</button>
<button class="sort-control-option" data-value="downloads">downloads</button>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion app/test/frontend/golden/search_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ <h3 class="search-form-section-header foldable-button">
<button class="sort-control-option" data-value="created">newest package</button>
<button class="sort-control-option" data-value="like">most likes</button>
<button class="sort-control-option" data-value="points">most pub points</button>
<button class="sort-control-option" data-value="popularity">popularity</button>
<button class="sort-control-option" data-value="downloads">downloads</button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/test/frontend/handlers/custom_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ void main() {
fn: () async {
final rs = await issueGet('/api/packages/oxygen/score');
final map = json.decode(await rs.readAsString());
// TODO: investigate why the download counts are missing here
expect(map, {
'grantedPoints': greaterThan(10),
'maxPoints': greaterThan(50),
'likeCount': 0,
'popularityScore': greaterThan(0),
'tags': contains('sdk:dart'),
'lastUpdated': isNotEmpty,
});
Expand Down
6 changes: 3 additions & 3 deletions app/test/search/handlers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ void main() {
['oxygen', 'neon', 'flutter_titanium'],
);
expect(
await queryPackageOrder('/packages?sort=popularity'),
['flutter_titanium', 'neon', 'oxygen'],
await queryPackageOrder('/packages?sort=downloads'),
['oxygen', 'flutter_titanium', 'neon'],
);
expect(
await queryPackageOrder('/packages?sort=popularity&q=sort:points'),
await queryPackageOrder('/packages?sort=downloads&q=sort:points'),
['oxygen', 'neon', 'flutter_titanium'],
);
},
Expand Down
2 changes: 1 addition & 1 deletion app/test/task/end2end_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import '../shared/utils.dart';
const String goldenDir = 'test/task/testdata/goldens';

// TODO: generalize golden testing, use env var for regenerating all goldens.
final _regenerateGoldens = true;
final _regenerateGoldens = false;

// We use a small test profile without flutter packages, because we have to
// run pana+dartdoc for all these package versions, naturally this is slow.
Expand Down
2 changes: 0 additions & 2 deletions pkg/_pub_shared/lib/data/package_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ class VersionScore {
final int? maxPoints;
final int? likeCount;
final int? downloadCount30Days;
final double? popularityScore;
final List<String>? tags;
final DateTime? lastUpdated;

Expand All @@ -289,7 +288,6 @@ class VersionScore {
required this.maxPoints,
required this.likeCount,
required this.downloadCount30Days,
required this.popularityScore,
required this.tags,
required this.lastUpdated,
});
Expand Down
2 changes: 0 additions & 2 deletions pkg/_pub_shared/lib/data/package_api.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9592cc1

Please sign in to comment.