Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions app/lib/account/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserSessionRow> createOrUpdateClientSession({
String? sessionId,
}) async {
Future<UserSession> createOrUpdateClientSession({String? sessionId}) async {
final now = clock.now().toUtc();
final expires = now.add(_sessionDuration);

Expand Down Expand Up @@ -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<SessionData> updateClientSessionWithProfile({
required String sessionId,
Expand Down Expand Up @@ -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<UserSessionRow?> lookupValidUserSession(String sessionId) async {
UserSessionRow? session;
Future<UserSession?> lookupValidUserSession(String sessionId) async {
UserSession? session;
try {
session = await primaryDatabase.withRetry(
(db) => db.userSessions.byKey(sessionId).fetch(),
Expand All @@ -622,7 +620,7 @@ class AccountBackend {
}

/// Upserts a session with the given fields into the SQL database.
Future<UserSessionRow> writeUserSessionToSql({
Future<UserSession> writeUserSessionToSql({
required String sessionId,
String? userId,
String? email,
Expand Down
17 changes: 3 additions & 14 deletions app/lib/account/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
/// 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());
}
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions app/lib/admin/tools/delete_all_staging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -48,7 +47,6 @@ Future<String> executeDeleteAllStaging(List<String> args) async {
final entities = <Query, int>{
dbService.query<AuditLogRecord>(): 500,
dbService.query<OAuthUserID>(): 500,
dbService.query<UserSession>(): 500,
dbService.query<User>(): 500,
dbService.query<Like>(): 500,
dbService.query<PackageVersionInfo>(): 500,
Expand All @@ -60,7 +58,6 @@ Future<String> executeDeleteAllStaging(List<String> args) async {
dbService.query<Publisher>(): 500,
dbService.query<ModeratedPackage>(): 500,
dbService.query<NeatTaskStatus>(): 500,
dbService.query<PackageState>(): 100,
};

final pool = Pool(concurrency);
Expand Down
4 changes: 1 addition & 3 deletions app/lib/database/schema.account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion app/lib/database/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ part 'schema.task.dart';
abstract final class PrimarySchema extends Schema {
// account tables

Table<UserSessionRow> get userSessions;
Table<UserSession> get userSessions;

// global lock table

Expand Down
Loading
Loading