feat: lazily load sqlite media artwork

This commit is contained in:
ngfchl
2026-07-18 13:43:22 +08:00
parent c7ba13e7bf
commit 3557c38db7
3 changed files with 68 additions and 10 deletions
+34
View File
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:path/path.dart' as path;
import 'package:sqflite/sqflite.dart';
@@ -95,6 +96,7 @@ class MediaLibraryStore {
Future<List<MediaLibraryItem>> items({String? libraryID}) async {
final rows = await (await _db).query(
'media_items',
columns: _itemMetadataColumns,
where: libraryID == null ? null : 'library_id = ?',
whereArgs: libraryID == null ? null : [libraryID],
orderBy: 'title COLLATE NOCASE',
@@ -102,6 +104,18 @@ class MediaLibraryStore {
return rows.map(_itemFromRow).toList();
}
Future<Uint8List?> posterBytes(String libraryID, String fileID) async {
final rows = await (await _db).query(
'media_items',
columns: const ['poster'],
where: 'library_id = ? AND file_id = ?',
whereArgs: [libraryID, fileID],
limit: 1,
);
final value = rows.isEmpty ? null : rows.first['poster'];
return value is Uint8List ? value : null;
}
Future<void> saveLibraries(List<MediaLibraryDefinition> libraries) async {
final db = await _db;
await db.transaction((txn) async {
@@ -467,5 +481,25 @@ class MediaLibraryStore {
}
static const _rootFolderID = '@root';
static const _itemMetadataColumns = [
'library_id',
'file_id',
'resource_path',
'cloud_name',
'file_size',
'gcid',
'file_type',
'tmdb_id',
'media_kind',
'title',
'original_title',
'release_date',
'overview',
'has_chinese_audio',
'has_chinese_subtitle',
'collection_id',
'collection_name',
'updated_at',
];
static String _folderID(String? folderID) => folderID ?? _rootFolderID;
}