diff --git a/app/lib/account/backend.dart b/app/lib/account/backend.dart index fc3117ad05..17ad1da009 100644 --- a/app/lib/account/backend.dart +++ b/app/lib/account/backend.dart @@ -425,9 +425,7 @@ class AccountBackend { /// Updates an existing or creates a new client session for pre-authorization /// secrets and post-authorization user information. - Future createOrUpdateClientSession({ - String? sessionId, - }) async { + Future createOrUpdateClientSession({String? sessionId}) async { final now = clock.now().toUtc(); final expires = now.add(_sessionDuration); @@ -459,7 +457,7 @@ class AccountBackend { ); } - /// Updates the [UserSessionRow] with the authenticated profile information. + /// Updates the [UserSession] with the authenticated profile information. /// Returns the new [SessionData] that is also populated in the cache. Future updateClientSessionWithProfile({ required String sessionId, @@ -596,13 +594,13 @@ class AccountBackend { return data; } - /// Returns the [UserSessionRow] associated with the [sessionId] or + /// Returns the [UserSession] associated with the [sessionId] or /// `null` if it does not exists. /// /// Deletes the session entry if it has already expired and /// clears the related cache too. - Future lookupValidUserSession(String sessionId) async { - UserSessionRow? session; + Future lookupValidUserSession(String sessionId) async { + UserSession? session; try { session = await primaryDatabase.withRetry( (db) => db.userSessions.byKey(sessionId).fetch(), @@ -622,7 +620,7 @@ class AccountBackend { } /// Upserts a session with the given fields into the SQL database. - Future writeUserSessionToSql({ + Future writeUserSessionToSql({ required String sessionId, String? userId, String? email, diff --git a/app/lib/account/models.dart b/app/lib/account/models.dart index d4191c6bb1..4d152023f8 100644 --- a/app/lib/account/models.dart +++ b/app/lib/account/models.dart @@ -157,19 +157,8 @@ class LikeData { } } -/// Tracks the client session, optionally with authenticated -/// userId and cached profile information. -@db.Kind(name: 'UserSession', idType: db.IdType.String) -class UserSession extends db.ExpandoModel { - /// Same as [id]. - /// This is a v4 (random) UUID String. - String get sessionId => id as String; - - UserSession(); -} - /// Convenience helpers for the SQL-backed session row. -extension UserSessionRowExt on UserSessionRow { +extension UserSessionExt on UserSession { bool isExpired() => clock.now().isAfter(expires); Duration get maxAge => expires.difference(clock.now()); } @@ -181,7 +170,7 @@ final _imgParamPattern = RegExp( r'=(?:(?:[swh]\d+)|[cp])(?:-(?:(?:[swh]\d+)|[cp]))*$', ); -/// The cacheable version of [UserSessionRow]. +/// The cacheable version of [UserSession]. @JsonSerializable() class SessionData { /// This is a v4 (random) UUID String that is set as a http cookie. @@ -228,7 +217,7 @@ class SessionData { this.grantedScopes, }); - factory SessionData.fromRow(UserSessionRow row) { + factory SessionData.fromRow(UserSession row) { return SessionData( sessionId: row.sessionId, userId: row.userId, diff --git a/app/lib/admin/tools/delete_all_staging.dart b/app/lib/admin/tools/delete_all_staging.dart index 8de2b15983..c2adb8b60c 100644 --- a/app/lib/admin/tools/delete_all_staging.dart +++ b/app/lib/admin/tools/delete_all_staging.dart @@ -11,7 +11,6 @@ import '../../package/models.dart'; import '../../publisher/models.dart'; import '../../shared/datastore.dart'; import '../../shared/env_config.dart'; -import '../../task/models.dart'; import '../../tool/neat_task/datastore_status_provider.dart'; final _argParser = ArgParser() @@ -48,7 +47,6 @@ Future executeDeleteAllStaging(List args) async { final entities = { dbService.query(): 500, dbService.query(): 500, - dbService.query(): 500, dbService.query(): 500, dbService.query(): 500, dbService.query(): 500, @@ -60,7 +58,6 @@ Future executeDeleteAllStaging(List args) async { dbService.query(): 500, dbService.query(): 500, dbService.query(): 500, - dbService.query(): 100, }; final pool = Pool(concurrency); diff --git a/app/lib/database/schema.account.dart b/app/lib/database/schema.account.dart index 4b1ff635bb..b0f8ee26e0 100644 --- a/app/lib/database/schema.account.dart +++ b/app/lib/database/schema.account.dart @@ -6,10 +6,8 @@ part of 'schema.dart'; /// Tracks the client session, optionally with authenticated /// userId and cached profile information. -/// -/// TODO: rename to `UserSession` after the Datastore migration is completed. @PrimaryKey(['sessionId']) -abstract final class UserSessionRow extends Row { +abstract final class UserSession extends Row { /// The session ID, a random UUID String. String get sessionId; diff --git a/app/lib/database/schema.dart b/app/lib/database/schema.dart index 9fd571bc38..214156c37b 100644 --- a/app/lib/database/schema.dart +++ b/app/lib/database/schema.dart @@ -17,7 +17,7 @@ part 'schema.task.dart'; abstract final class PrimarySchema extends Schema { // account tables - Table get userSessions; + Table get userSessions; // global lock table diff --git a/app/lib/database/schema.g.dart b/app/lib/database/schema.g.dart index 193861df78..1a13044cad 100644 --- a/app/lib/database/schema.g.dart +++ b/app/lib/database/schema.g.dart @@ -30,7 +30,7 @@ Map _$TaskStateToJson(TaskState instance) => { /// Extension methods for a [Database] operating on [PrimarySchema]. extension PrimarySchemaSchema on Database { static final _$tables = [ - _$UserSessionRow._$table, + _$UserSession._$table, _$GlobalLockStateRow._$table, _$Task._$table, _$TaskDependency._$table, @@ -38,8 +38,8 @@ extension PrimarySchemaSchema on Database { _$TaskAbortedToken._$table, ]; - Table get userSessions => - $ForGeneratedCode.declareTable(this, _$UserSessionRow._$table); + Table get userSessions => + $ForGeneratedCode.declareTable(this, _$UserSession._$table); Table get globalLockStates => $ForGeneratedCode.declareTable(this, _$GlobalLockStateRow._$table); @@ -85,8 +85,8 @@ extension PrimarySchemaSchema on Database { String createPrimarySchemaTables(SqlDialect dialect) => $ForGeneratedCode .createTableSchema(dialect: dialect, tables: PrimarySchemaSchema._$tables); -final class _$UserSessionRow extends UserSessionRow { - _$UserSessionRow._( +final class _$UserSession extends UserSession { + _$UserSession._( this.sessionId, this.userId, this.email, @@ -254,10 +254,10 @@ final class _$UserSessionRow extends UserSessionRow { columns: ['expires'], ), ], - readRow: _$UserSessionRow._$fromDatabase, + readRow: _$UserSession._$fromDatabase, ); - static UserSessionRow? _$fromDatabase(RowReader row) { + static UserSession? _$fromDatabase(RowReader row) { final sessionId = row.readString(); final userId = row.readString(); final email = row.readString(); @@ -284,7 +284,7 @@ final class _$UserSessionRow extends UserSessionRow { grantedScopes == null) { return null; } - return _$UserSessionRow._( + return _$UserSession._( sessionId!, userId, email, @@ -302,16 +302,16 @@ final class _$UserSessionRow extends UserSessionRow { @override String toString() => - 'UserSessionRow(sessionId: "$sessionId", userId: "$userId", email: "$email", name: "$name", imageUrl: "$imageUrl", created: "$created", expires: "$expires", authenticatedAt: "$authenticatedAt", csrfToken: "$csrfToken", openidNonce: "$openidNonce", accessToken: "$accessToken", grantedScopes: "$grantedScopes")'; + 'UserSession(sessionId: "$sessionId", userId: "$userId", email: "$email", name: "$name", imageUrl: "$imageUrl", created: "$created", expires: "$expires", authenticatedAt: "$authenticatedAt", csrfToken: "$csrfToken", openidNonce: "$openidNonce", accessToken: "$accessToken", grantedScopes: "$grantedScopes")'; } -/// Extension methods for table defined in [UserSessionRow]. -extension TableUserSessionRowExt on Table { +/// Extension methods for table defined in [UserSession]. +extension TableUserSessionExt on Table { /// Insert row into the `userSessions` table. /// /// Returns a [InsertSingle] statement on which `.execute` must be /// called for the row to be inserted. - InsertSingle insert({ + InsertSingle insert({ required Expr sessionId, Expr? userId, Expr? email, @@ -346,7 +346,7 @@ extension TableUserSessionRowExt on Table { /// /// Returns a [InsertSingle] statement on which `.execute` must be /// called for the row to be inserted. - InsertSingle insertValue({ + InsertSingle insertValue({ required String sessionId, String? userId, String? email, @@ -394,7 +394,7 @@ extension TableUserSessionRowExt on Table { /// /// Returns a [Insert] statement on which `.execute` must be /// called for the rows to be inserted. - Insert insertValuesMapped( + Insert insertValuesMapped( Iterable rows, { required String Function(T row) sessionId, String? Function(T row)? userId, @@ -436,18 +436,18 @@ extension TableUserSessionRowExt on Table { /// To delete multiple rows, using `.where()` to filter which rows /// should be deleted. If you wish to delete all rows, use /// `.where((_) => toExpr(true)).delete()`. - DeleteSingle delete(String sessionId) => $ForGeneratedCode - .deleteSingle(byKey(sessionId), _$UserSessionRow._$table); + DeleteSingle delete(String sessionId) => + $ForGeneratedCode.deleteSingle(byKey(sessionId), _$UserSession._$table); } /// Extension methods for building queries against the `userSessions` table. -extension QueryUserSessionRowExt on Query<(Expr,)> { +extension QueryUserSessionExt on Query<(Expr,)> { /// Lookup a single row in `userSessions` table using the _primary key_. /// /// Returns a [QuerySingle] object, which returns at-most one row, /// when `.fetch()` is called. - QuerySingle<(Expr,)> byKey(String sessionId) => where( - (userSessionRow) => userSessionRow.sessionId.equalsValue(sessionId), + QuerySingle<(Expr,)> byKey(String sessionId) => where( + (userSession) => userSession.sessionId.equalsValue(sessionId), ).first; /// Update all rows in the `userSessions` table matching this [Query]. @@ -477,10 +477,10 @@ extension QueryUserSessionRowExt on Query<(Expr,)> { /// > the expressions for updating the rows. You should **never** invoke /// > the `set` function more than once, and the result should always /// > be returned immediately. - Update update( - UpdateSet Function( - Expr userSessionRow, - UpdateSet Function({ + Update update( + UpdateSet Function( + Expr userSession, + UpdateSet Function({ Expr sessionId, Expr userId, Expr email, @@ -497,11 +497,11 @@ extension QueryUserSessionRowExt on Query<(Expr,)> { set, ) updateBuilder, - ) => $ForGeneratedCode.update( + ) => $ForGeneratedCode.update( this, - _$UserSessionRow._$table, - (userSessionRow) => updateBuilder( - userSessionRow, + _$UserSession._$table, + (userSession) => updateBuilder( + userSession, ({ Expr? sessionId, Expr? userId, @@ -515,7 +515,7 @@ extension QueryUserSessionRowExt on Query<(Expr,)> { Expr? openidNonce, Expr? accessToken, Expr? grantedScopes, - }) => $ForGeneratedCode.buildUpdate([ + }) => $ForGeneratedCode.buildUpdate([ sessionId, userId, email, @@ -536,12 +536,12 @@ extension QueryUserSessionRowExt on Query<(Expr,)> { /// /// Returns a [Delete] statement on which `.execute()` must be called /// for the rows to be deleted. - Delete delete() => - $ForGeneratedCode.delete(this, _$UserSessionRow._$table); + Delete delete() => + $ForGeneratedCode.delete(this, _$UserSession._$table); } /// Extension methods for building point queries against the `userSessions` table. -extension QuerySingleUserSessionRowExt on QuerySingle<(Expr,)> { +extension QuerySingleUserSessionExt on QuerySingle<(Expr,)> { /// Update the row (if any) in the `userSessions` table matching this /// [QuerySingle]. /// @@ -571,10 +571,10 @@ extension QuerySingleUserSessionRowExt on QuerySingle<(Expr,)> { /// > the expressions for updating the rows. You should **never** invoke /// > the `set` function more than once, and the result should always /// > be returned immediately. - UpdateSingle update( - UpdateSet Function( - Expr userSessionRow, - UpdateSet Function({ + UpdateSingle update( + UpdateSet Function( + Expr userSession, + UpdateSet Function({ Expr sessionId, Expr userId, Expr email, @@ -591,11 +591,11 @@ extension QuerySingleUserSessionRowExt on QuerySingle<(Expr,)> { set, ) updateBuilder, - ) => $ForGeneratedCode.updateSingle( + ) => $ForGeneratedCode.updateSingle( this, - _$UserSessionRow._$table, - (userSessionRow) => updateBuilder( - userSessionRow, + _$UserSession._$table, + (userSession) => updateBuilder( + userSession, ({ Expr? sessionId, Expr? userId, @@ -609,7 +609,7 @@ extension QuerySingleUserSessionRowExt on QuerySingle<(Expr,)> { Expr? openidNonce, Expr? accessToken, Expr? grantedScopes, - }) => $ForGeneratedCode.buildUpdate([ + }) => $ForGeneratedCode.buildUpdate([ sessionId, userId, email, @@ -631,12 +631,12 @@ extension QuerySingleUserSessionRowExt on QuerySingle<(Expr,)> { /// Returns a [DeleteSingle] statement on which `.execute()` must be called /// for the row to be deleted. The resulting statement will **not** /// fail, if there are no rows matching this query exists. - DeleteSingle delete() => - $ForGeneratedCode.deleteSingle(this, _$UserSessionRow._$table); + DeleteSingle delete() => + $ForGeneratedCode.deleteSingle(this, _$UserSession._$table); } /// Extension methods for expressions on a row in the `userSessions` table. -extension ExpressionUserSessionRowExt on Expr { +extension ExpressionUserSessionExt on Expr { /// The session ID, a random UUID String. Expr get sessionId => $ForGeneratedCode.field(this, 0, $ForGeneratedCode.text); @@ -686,7 +686,7 @@ extension ExpressionUserSessionRowExt on Expr { $ForGeneratedCode.field(this, 11, $ForGeneratedCode.text); } -extension ExpressionNullableUserSessionRowExt on Expr { +extension ExpressionNullableUserSessionExt on Expr { /// The session ID, a random UUID String. Expr get sessionId => $ForGeneratedCode.field(this, 0, $ForGeneratedCode.text); @@ -752,20 +752,20 @@ extension ExpressionNullableUserSessionRowExt on Expr { Expr isNull() => isNotNull().not(); } -/// `Table` conflict targets for use with `.onConflict`. -enum UserSessionRowConflict { +/// `Table` conflict targets for use with `.onConflict`. +enum UserSessionConflict { /// Conflict with an existing row that has a matching primary key. /// /// Thus, the other row has matching values for: /// `sessionId`. primaryKey(['session_id']); - const UserSessionRowConflict(this._fields); + const UserSessionConflict(this._fields); final List _fields; } -extension InsertUserSessionRowExt on Insert { +extension InsertUserSessionExt on Insert { /// Build an `INSERT` statement with an `ON CONFLICT` clause. /// /// The [target] argument specifies the _conflict target_ to be @@ -775,7 +775,7 @@ extension InsertUserSessionRowExt on Insert { /// If a row to be inserted violates the _conflict target_ constraint, /// then the conflict action is triggered: /// * `.doNothing()` to skip insertion of the new row, and, - /// * `.update((userSessionRow, excluded, set) => set(...))` to + /// * `.update((userSession, excluded, set) => set(...))` to /// update the conflicting row. /// /// If a row to be inserted violates a constraint other than the one @@ -783,19 +783,18 @@ extension InsertUserSessionRowExt on Insert { /// will fail. /// /// This is equivalent to `INSERT ... ON CONFLICT (...)` in SQL. - InsertOnConflict onConflict(UserSessionRowConflict target) => + InsertOnConflict onConflict(UserSessionConflict target) => $ForGeneratedCode.insertOnConflict(this, target._fields); } -extension InsertOnConflictUserSessionRowExt - on InsertOnConflict { +extension InsertOnConflictUserSessionExt on InsertOnConflict { /// Build an `INSERT` statement an [upsert-clause][1]. /// /// When a row to be inserted violates the `UNIQUE` or `PRIMARY KEY` /// constraint previously specified as _conflict target_, the existing /// row is updated using the expressions defined with the /// [updateBuilder]. The [updateBuilder] is given 3 parameters: - /// * `userSessionRow` an [Expr] representing the existing row in + /// * `userSession` an [Expr] representing the existing row in /// the database, /// * `excluded` an [Expr] representing the row to be inserted in the /// database, and, @@ -829,11 +828,11 @@ extension InsertOnConflictUserSessionRowExt /// > be returned immediately. /// /// [1]: https://www.sqlite.org/lang_upsert.html - Upsert update( - UpdateSet Function( - Expr userSessionRow, - Expr excluded, - UpdateSet Function({ + Upsert update( + UpdateSet Function( + Expr userSession, + Expr excluded, + UpdateSet Function({ Expr sessionId, Expr userId, Expr email, @@ -850,10 +849,10 @@ extension InsertOnConflictUserSessionRowExt set, ) updateBuilder, - ) => $ForGeneratedCode.updateOnConflict( + ) => $ForGeneratedCode.updateOnConflict( this, - (userSessionRow, excluded) => updateBuilder( - userSessionRow, + (userSession, excluded) => updateBuilder( + userSession, excluded, ({ Expr? sessionId, @@ -868,7 +867,7 @@ extension InsertOnConflictUserSessionRowExt Expr? openidNonce, Expr? accessToken, Expr? grantedScopes, - }) => $ForGeneratedCode.buildUpdate([ + }) => $ForGeneratedCode.buildUpdate([ sessionId, userId, email, @@ -886,7 +885,7 @@ extension InsertOnConflictUserSessionRowExt ); } -extension InsertSingleUserSessionRowExt on InsertSingle { +extension InsertSingleUserSessionExt on InsertSingle { /// Build an `INSERT` statement with an `ON CONFLICT` clause. /// /// The [target] argument specifies the _conflict target_ to be @@ -896,7 +895,7 @@ extension InsertSingleUserSessionRowExt on InsertSingle { /// If a row to be inserted violates the _conflict target_ constraint, /// then the conflict action is triggered: /// * `.doNothing()` to skip insertion of the new row, and, - /// * `.update((userSessionRow, excluded, set) => set(...))` to + /// * `.update((userSession, excluded, set) => set(...))` to /// update the conflicting row. /// /// If a row to be inserted violates a constraint other than the one @@ -904,20 +903,19 @@ extension InsertSingleUserSessionRowExt on InsertSingle { /// will fail. /// /// This is equivalent to `INSERT ... ON CONFLICT (...)` in SQL. - InsertOnConflictSingle onConflict( - UserSessionRowConflict target, - ) => $ForGeneratedCode.insertOnConflictSingle(this, target._fields); + InsertOnConflictSingle onConflict(UserSessionConflict target) => + $ForGeneratedCode.insertOnConflictSingle(this, target._fields); } -extension InsertOnConflictSingleUserSessionRowExt - on InsertOnConflictSingle { +extension InsertOnConflictSingleUserSessionExt + on InsertOnConflictSingle { /// Build an `INSERT` statement an [upsert-clause][1]. /// /// When a row to be inserted violates the `UNIQUE` or `PRIMARY KEY` /// constraint previously specified as _conflict target_, the existing /// row is updated using the expressions defined with the /// [updateBuilder]. The [updateBuilder] is given 3 parameters: - /// * `userSessionRow` an [Expr] representing the existing row in + /// * `userSession` an [Expr] representing the existing row in /// the database, /// * `excluded` an [Expr] representing the row to be inserted in the /// database, and, @@ -951,11 +949,11 @@ extension InsertOnConflictSingleUserSessionRowExt /// > be returned immediately. /// /// [1]: https://www.sqlite.org/lang_upsert.html - UpsertSingle update( - UpdateSet Function( - Expr userSessionRow, - Expr excluded, - UpdateSet Function({ + UpsertSingle update( + UpdateSet Function( + Expr userSession, + Expr excluded, + UpdateSet Function({ Expr sessionId, Expr userId, Expr email, @@ -972,10 +970,10 @@ extension InsertOnConflictSingleUserSessionRowExt set, ) updateBuilder, - ) => $ForGeneratedCode.updateOnConflictSingle( + ) => $ForGeneratedCode.updateOnConflictSingle( this, - (userSessionRow, excluded) => updateBuilder( - userSessionRow, + (userSession, excluded) => updateBuilder( + userSession, excluded, ({ Expr? sessionId, @@ -990,7 +988,7 @@ extension InsertOnConflictSingleUserSessionRowExt Expr? openidNonce, Expr? accessToken, Expr? grantedScopes, - }) => $ForGeneratedCode.buildUpdate([ + }) => $ForGeneratedCode.buildUpdate([ sessionId, userId, email, diff --git a/app/lib/task/models.dart b/app/lib/task/models.dart index c146758799..9e38fb095a 100644 --- a/app/lib/task/models.dart +++ b/app/lib/task/models.dart @@ -68,18 +68,9 @@ final initialTimestamp = DateTime.fromMillisecondsSinceEpoch(0, isUtc: true); Duration taskRetryDelay(int attempts) => Duration(hours: 3) * (attempts * attempts); -/// [PackageState] is used for storing the analysis state of a package for a -/// given `runtimeVersion`. -/// -/// * `id`, is the `runtimeVersion / packageName`. -/// * `PackageState` entities never have a parent. -@db.Kind(name: 'PackageState', idType: db.IdType.String) -@Deprecated('No longer in use.') -class PackageState extends db.ExpandoModel {} - /// Derive the `pendingAt` field using [versions] and [lastDependencyChanged]. /// -/// When updating PackageState the pendingAt property is set to the minimum of: +/// When updating Task the pendingAt property is set to the minimum of: /// * `scheduled + 31 days` for any version, /// * `scheduled + 24 hours` for any version where `dependencyChanged > scheduled` /// * `scheduled + 3 hours * attempts^2` for any version where `attempts > 0 && attempts < 3`. diff --git a/app/lib/tool/backfill/backfill_new_fields.dart b/app/lib/tool/backfill/backfill_new_fields.dart index ab58804a46..92a30290d1 100644 --- a/app/lib/tool/backfill/backfill_new_fields.dart +++ b/app/lib/tool/backfill/backfill_new_fields.dart @@ -5,10 +5,8 @@ import 'dart:convert'; import 'package:logging/logging.dart'; -import 'package:pub_dev/account/models.dart'; import 'package:pub_dev/package/models.dart'; import 'package:pub_dev/shared/datastore.dart'; -import 'package:pub_dev/task/models.dart'; final _logger = Logger('backfill_new_fields'); @@ -56,9 +54,4 @@ Future backfillNewFields() async { }); } } - _logger.info('Delete old TaskState entities in Datastore'); - await dbService.deleteWithQuery(dbService.query()); - - _logger.info('Delete old UserSession entities in Datastore'); - await dbService.deleteWithQuery(dbService.query()); } diff --git a/index.yaml b/index.yaml index d3a294ea81..38d7750b2a 100644 --- a/index.yaml +++ b/index.yaml @@ -60,16 +60,6 @@ indexes: - name: created direction: desc -- kind: PackageState - properties: - - name: runtimeVersion - - name: pendingAt - -- kind: PackageState - properties: - - name: dependencies - - name: lastDependencyChanged - # AUTOGENERATED # This index.yaml is automatically updated whenever the dev_appserver