Merge the deduplication and dead-code removal pass

Consolidates duplicated logic behind shared implementations — paginated
grid tabs, focus chrome, cached remote stores, sheet selection columns,
the server artifact store and a test fixture layer — and removes code
that had become unreachable. Net reduction of about 5,500 lines with no
behaviour change.

Where a fix had landed separately in code that moved into a shared
helper, the fix was re-applied inside the helper rather than left behind
in the copy that went away.
This commit is contained in:
edde746
2026-07-26 19:41:23 +02:00
425 changed files with 12045 additions and 17543 deletions
+3 -2
View File
@@ -20,6 +20,7 @@ import 'package:plezy/utils/active_client_scope.dart';
import 'package:plezy/utils/media_server_http_client.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import '../test_helpers/download_fixtures.dart';
import '../test_helpers/prefs.dart';
final class _EnsureOpenTrackingInterceptor extends QueryInterceptor {
@@ -81,8 +82,8 @@ class _AppDatabaseTestSuite {
// v20 dropped the profile_id FK so virtual Plex Home profiles can
// persist join rows without a parent `profiles` row. Profile deletion
// instead cleans up join rows explicitly (via the teardown flow's
// removeAllProfileConnectionsAndCleanup) before deleting the profile,
// so the cascade isn't needed.
// ProfileConnectionCleanup.removeAllProfileConnections) before deleting
// the profile, so the cascade isn't needed.
final now = DateTime.now().millisecondsSinceEpoch;
await db
.into(db.connections)
+2 -109
View File
@@ -9,6 +9,8 @@ import 'package:plezy/database/app_database.dart';
import 'package:plezy/database/download_operations.dart';
import 'package:plezy/models/download_models.dart';
import '../test_helpers/download_fixtures.dart';
void main() {
late AppDatabase db;
@@ -20,115 +22,6 @@ void main() {
await db.close();
});
// ============================================================
// insertDownload
// ============================================================
group('insertDownload', () {
test('inserts a movie row with defaults', () async {
await db.insertDownload(
serverId: ServerId('srv'),
ratingKey: '100',
globalKey: 'srv:100',
type: 'movie',
status: DownloadStatus.queued.index,
);
final rows = await db.select(db.downloadedMedia).get();
expect(rows, hasLength(1));
final r = rows.first;
expect(r.serverId, 'srv');
expect(r.ratingKey, '100');
expect(r.globalKey, 'srv:100');
expect(r.type, 'movie');
expect(r.status, DownloadStatus.queued.index);
expect(r.parentRatingKey, isNull);
expect(r.grandparentRatingKey, isNull);
expect(r.mediaIndex, 0);
});
test('inserts an episode with parent and grandparent keys', () async {
await db.insertDownload(
serverId: ServerId('srv'),
ratingKey: 'ep1',
globalKey: 'srv:ep1',
type: 'episode',
parentRatingKey: 'season1',
grandparentRatingKey: 'show1',
status: DownloadStatus.queued.index,
mediaIndex: 7,
);
final row = (await db.select(db.downloadedMedia).get()).single;
expect(row.parentRatingKey, 'season1');
expect(row.grandparentRatingKey, 'show1');
expect(row.mediaIndex, 7);
});
test('atomically updates metadata and attempt state while preserving the row and physical fields', () async {
await db.insertDownload(
serverId: ServerId('srv'),
clientScopeId: 'scope-old',
ratingKey: '100',
globalKey: 'srv:100',
type: 'movie',
status: DownloadStatus.queued.index,
mediaIndex: 1,
mediaSourceId: 'source-old',
);
final original = (await db.getDownloadedMedia('srv:100'))!;
await (db.update(db.downloadedMedia)..where((row) => row.globalKey.equals('srv:100'))).write(
const DownloadedMediaCompanion(
progress: Value(50),
downloadedBytes: Value(500),
totalBytes: Value(1000),
videoFilePath: Value('downloads/video.mkv'),
safRootUri: Value('content://downloads'),
thumbPath: Value('downloads/thumb.jpg'),
downloadedAt: Value(1234),
errorMessage: Value('old error'),
retryCount: Value(2),
bgTaskId: Value('current-task'),
),
);
await db.insertDownload(
serverId: ServerId('srv-new'),
clientScopeId: 'scope-new',
ratingKey: '100-new',
globalKey: 'srv:100',
type: 'episode',
parentRatingKey: 'season-new',
grandparentRatingKey: 'show-new',
status: DownloadStatus.failed.index,
mediaIndex: 3,
mediaSourceId: 'source-new',
);
final row = (await db.select(db.downloadedMedia).get()).single;
expect(row.id, original.id);
expect(row.serverId, 'srv-new');
expect(row.clientScopeId, 'scope-new');
expect(row.ratingKey, '100-new');
expect(row.type, 'episode');
expect(row.parentRatingKey, 'season-new');
expect(row.grandparentRatingKey, 'show-new');
expect(row.status, DownloadStatus.failed.index);
expect(row.mediaIndex, 3);
expect(row.mediaSourceId, 'source-new');
expect(row.progress, 0);
expect(row.downloadedBytes, 0);
expect(row.totalBytes, isNull);
expect(row.errorMessage, isNull);
expect(row.retryCount, 0);
expect(row.videoFilePath, 'downloads/video.mkv');
expect(row.safRootUri, 'content://downloads');
expect(row.thumbPath, 'downloads/thumb.jpg');
expect(row.downloadedAt, 1234);
expect(row.bgTaskId, 'current-task');
});
});
group('insertQueuedDownload', () {
test('atomically persists media identity, scope, policy, and queue state', () async {
await db.close();