Skip to content

Commit

Permalink
Remove isBlocked fields + starting to remove them from Datastore. (da…
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 14, 2025
1 parent 66ba85b commit c2e1e05
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 46 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ 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)
* Bump runtimeVersion to `2025.01.15`.
* Note: started deleting `Package.isBlocked`, `Publisher.isBlocked`, `User.isBlocked`.

## `20250114t095800-all`
* Bump runtimeVersion to `2025.01.14`.
Expand Down
8 changes: 0 additions & 8 deletions app/lib/account/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ class User extends db.ExpandoModel<String> {
@db.BoolProperty(required: true)
bool isDeleted = false;

/// [isBlocked] is set when a user account is blocked (is on administrative hold).
/// When this happens user-data is preserved, but the user should not be able
/// to perform any action.
///
/// TODO: remove after runtime version `2024.12.17` is no longer running.
@db.BoolProperty(required: false)
bool isBlocked = false;

/// `true` if user was moderated (pending moderation or deletion).
@db.BoolProperty(required: true)
bool isModerated = false;
Expand Down
10 changes: 1 addition & 9 deletions app/lib/package/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ class Package extends db.ExpandoModel<String> {
@db.BoolProperty(required: true)
bool isUnlisted = false;

/// Set to `true` if package should not be displayed anywhere, because of
/// pending moderation or deletion.
///
/// TODO: remove after runtime version `2024.12.17` is no longer running.
@db.BoolProperty(required: false)
bool isBlocked = false;

/// `true` if package was moderated (pending moderation or deletion).
@db.BoolProperty(required: true)
bool isModerated = false;
Expand Down Expand Up @@ -186,15 +179,14 @@ class Package extends db.ExpandoModel<String> {
..likes = 0
..isDiscontinued = false
..isUnlisted = false
..isBlocked = false
..isModerated = false
..assignedTags = []
..deletedVersions = [];
}

// Convenience Fields:

bool get isVisible => !isBlocked && !isModerated;
bool get isVisible => !isModerated;
bool get isNotVisible => !isVisible;

bool get isIncludedInRobots {
Expand Down
12 changes: 0 additions & 12 deletions app/lib/publisher/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ class Publisher extends db.ExpandoModel<String> {
@db.BoolProperty(required: true)
bool isAbandoned = false;

/// [isBlocked] is set when a [Publisher] is blocked by an administrative action.
/// When this happens:
/// - The publisher page should neither be visible nor listed anywhere.
/// - Administrator roles of the publisher must not be able to change any setting,
/// membership information, or invite new members.
/// - Administrator roles of the publisher must not be able to publisher a new version
/// for packages of the publisher, or change any of the existing package's properties.
///
/// TODO: remove after runtime version `2024.12.17` is no longer running.
@db.BoolProperty(required: false)
bool isBlocked = false;

/// `true` if publisher was moderated (pending moderation or deletion).
@db.BoolProperty(required: true)
bool isModerated = false;
Expand Down
7 changes: 4 additions & 3 deletions app/lib/shared/integrity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ final _random = math.Random.secure();
/// The presence of such fields won't be reported as integrity issue, only
/// the absent ones will be reported.
const _allowedUnmappedFields = {
'Package.isWithheld',
'Package.withheldReason',
'Package.isBlocked',
'Publisher.isBlocked',
'User.isBlocked',
};

/// Checks the integrity of the datastore.
Expand Down Expand Up @@ -441,7 +442,7 @@ class IntegrityChecker {
isModerated: p.isModerated,
moderatedAt: p.moderatedAt,
);
if (p.isModerated || p.isBlocked) {
if (p.isModerated) {
_packagesWithIsModeratedFlag.add(p.name!);
}

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].
'2025.01.14',
'2025.01.15',
// Fallback runtime versions.
'2025.01.14',
'2025.01.07',
'2024.12.17',
];

/// Sets the current runtime versions.
Expand Down
29 changes: 17 additions & 12 deletions app/lib/tool/backfill/backfill_new_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:logging/logging.dart';
import 'package:pub_dev/account/models.dart';
import 'package:pub_dev/package/models.dart';
import 'package:pub_dev/publisher/models.dart';
import 'package:pub_dev/shared/datastore.dart';

final _logger = Logger('backfill_new_fields');
Expand All @@ -19,19 +21,22 @@ Future<void> backfillNewFields() async {

Future<void> _removeKnownUnmappedFields() async {
_logger.info('Removing unmapped fields...');
await for (final p in dbService.query<Package>().run()) {
if (p.additionalProperties.isEmpty) continue;
if (p.additionalProperties.containsKey('automatedPublishingJson') ||
p.additionalProperties.containsKey('blocked') ||
p.additionalProperties.containsKey('blockedReason')) {
await withRetryTransaction(dbService, (tx) async {
final pkg = await tx.lookupValue<Package>(p.key);
pkg.additionalProperties.remove('automatedPublishingJson');
pkg.additionalProperties.remove('blocked');
pkg.additionalProperties.remove('blockedReason');
tx.insert(pkg);
});

Future<void> removeIsBlocked<T extends ExpandoModel>() async {
await for (final p in dbService.query<T>().run()) {
if (p.additionalProperties.isEmpty) continue;
if (p.additionalProperties.containsKey('isBlocked')) {
await withRetryTransaction(dbService, (tx) async {
final e = await tx.lookupValue<T>(p.key);
e.additionalProperties.remove('isBlocked');
tx.insert(e);
});
}
}
}

await removeIsBlocked<Package>();
await removeIsBlocked<Publisher>();
await removeIsBlocked<User>();
_logger.info('Removing unmapped fields completed.');
}

0 comments on commit c2e1e05

Please sign in to comment.