Skip to content

Commit

Permalink
Store popularity on PackageView. (#7120)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Oct 13, 2023
1 parent 580c93c commit e1f80c9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Important changes to data models, configuration, and migrations between each
AppEngine version, listed here to ease deployment and troubleshooting.

## Next Release (replace with git tag when deployed)
* Bumped runtimeVersion to `2023.10.13`.

## `20231012t082200-all`

Expand Down
10 changes: 6 additions & 4 deletions app/lib/package/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ class PackageView {
final List<ProcessedScreenshot>? screenshots;

final List<String>? topics;
final int popularity;

PackageView({
this.screenshots,
Expand All @@ -945,6 +946,7 @@ class PackageView {
this.spdxIdentifiers,
this.apiPages,
this.topics,
required this.popularity,
}) : isPending = isPending ?? false,
tags = tags ?? <String>[];

Expand All @@ -957,6 +959,7 @@ class PackageView {
PackageVersion? version,
required ScoreCardData scoreCard,
List<ApiPageRef>? apiPages,
required int popularity,
}) {
final tags = <String>{
...package.getTags(),
Expand All @@ -980,6 +983,7 @@ class PackageView {
apiPages: apiPages,
screenshots: scoreCard.panaReport?.screenshots,
topics: version?.pubspec?.topics,
popularity: popularity,
);
}

Expand All @@ -1000,6 +1004,7 @@ class PackageView {
apiPages: apiPages ?? this.apiPages,
screenshots: screenshots,
topics: topics,
popularity: popularity,
);
}

Expand All @@ -1008,9 +1013,6 @@ class PackageView {
bool get isDiscontinued => tags.contains(PackageTags.isDiscontinued);
bool get isLegacy => tags.contains(PackageVersionTags.isLegacy);
bool get isObsolete => tags.contains(PackageVersionTags.isObsolete);

// TODO: refactor code to use popularityStorage directly.
int get popularity => popularityStorage.lookupAsScore(name);
}

/// Sorts [versions] according to the semantic versioning specification.
Expand Down Expand Up @@ -1111,7 +1113,6 @@ class PackagePageData {
bool get hasPubspec => versionInfo.assets.contains(AssetKind.pubspec);

bool get isLatestStable => version.version == package.latestVersion;
int get popularity => popularityStorage.lookupAsScore(package.name!);

late final packageLinks = () {
// Trying to use verfied URLs
Expand Down Expand Up @@ -1151,6 +1152,7 @@ class PackagePageData {
releases: latestReleases,
version: version,
scoreCard: scoreCard,
popularity: popularityStorage.lookupAsScore(package.name!),
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/lib/package/models.g.dart

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

2 changes: 2 additions & 0 deletions app/lib/scorecard/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:pool/pool.dart';
import 'package:pub_dev/shared/exceptions.dart';
import 'package:pub_dev/shared/popularity_storage.dart';
import 'package:pub_dev/task/backend.dart';

import '../package/backend.dart';
Expand Down Expand Up @@ -95,6 +96,7 @@ class ScoreCardBackend {
releases: releases,
version: pv,
scoreCard: card,
popularity: popularityStorage.lookupAsScore(package),
);
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/shared/versions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ final RegExp runtimeVersionPattern = RegExp(r'^\d{4}\.\d{2}\.\d{2}$');
/// when the version switch happens.
const _acceptedRuntimeVersions = <String>[
// The current [runtimeVersion].
'2023.10.10',
'2023.10.13',
// Fallback runtime versions.
'2023.10.10',
'2023.09.26',
'2023.09.12',
];

/// Sets the current runtime versions.
Expand Down

0 comments on commit e1f80c9

Please sign in to comment.