mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-07-29 15:28:48 +02:00
perf(library): trim startup lookup index
This commit is contained in:
@@ -33,7 +33,6 @@ class LocalLibraryState {
|
||||
final int excludedDownloadedCount;
|
||||
final Set<String> _trackKeySet;
|
||||
final Set<String> _isrcSet;
|
||||
final Map<String, String> _filePathById;
|
||||
|
||||
LocalLibraryState({
|
||||
this.isScanning = false,
|
||||
@@ -50,10 +49,8 @@ class LocalLibraryState {
|
||||
this.excludedDownloadedCount = 0,
|
||||
Set<String>? trackKeySet,
|
||||
Set<String>? isrcSet,
|
||||
Map<String, String>? filePathById,
|
||||
}) : _trackKeySet = trackKeySet ?? const <String>{},
|
||||
_isrcSet = isrcSet ?? const <String>{},
|
||||
_filePathById = filePathById ?? const <String, String>{};
|
||||
_isrcSet = isrcSet ?? const <String>{};
|
||||
|
||||
bool hasIsrc(String isrc) => _isrcSet.contains(isrc);
|
||||
|
||||
@@ -62,8 +59,6 @@ class LocalLibraryState {
|
||||
return _trackKeySet.contains(key);
|
||||
}
|
||||
|
||||
String? filePathForId(String id) => _filePathById[id];
|
||||
|
||||
bool existsInLibrary({String? isrc, String? trackName, String? artistName}) {
|
||||
if (isrc != null && isrc.isNotEmpty && hasIsrc(isrc)) {
|
||||
return true;
|
||||
@@ -89,7 +84,6 @@ class LocalLibraryState {
|
||||
int? excludedDownloadedCount,
|
||||
Set<String>? trackKeySet,
|
||||
Set<String>? isrcSet,
|
||||
Map<String, String>? filePathById,
|
||||
}) {
|
||||
return LocalLibraryState(
|
||||
isScanning: isScanning ?? this.isScanning,
|
||||
@@ -107,7 +101,6 @@ class LocalLibraryState {
|
||||
excludedDownloadedCount ?? this.excludedDownloadedCount,
|
||||
trackKeySet: trackKeySet ?? _trackKeySet,
|
||||
isrcSet: isrcSet ?? _isrcSet,
|
||||
filePathById: filePathById ?? _filePathById,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -190,7 +183,6 @@ class LocalLibraryNotifier extends Notifier<LocalLibraryState> {
|
||||
excludedDownloadedCount: excludedDownloadedCount,
|
||||
trackKeySet: lookupIndex.matchKeys,
|
||||
isrcSet: lookupIndex.isrcs,
|
||||
filePathById: lookupIndex.filePathById,
|
||||
);
|
||||
_log.i(
|
||||
'Loaded local library summary: $count items, lastScannedAt: '
|
||||
@@ -227,7 +219,6 @@ class LocalLibraryNotifier extends Notifier<LocalLibraryState> {
|
||||
excludedDownloadedCount: excludedDownloadedCount,
|
||||
trackKeySet: index.matchKeys,
|
||||
isrcSet: index.isrcs,
|
||||
filePathById: index.filePathById,
|
||||
);
|
||||
_hasLoadedFromDatabase = true;
|
||||
_isLoaded = true;
|
||||
|
||||
@@ -208,12 +208,24 @@ class LocalLibraryAlbumGroup {
|
||||
class LocalLibraryLookupIndex {
|
||||
final Set<String> isrcs;
|
||||
final Set<String> matchKeys;
|
||||
final Map<String, String> filePathById;
|
||||
|
||||
const LocalLibraryLookupIndex({
|
||||
this.isrcs = const <String>{},
|
||||
this.matchKeys = const <String>{},
|
||||
this.filePathById = const <String, String>{},
|
||||
});
|
||||
}
|
||||
|
||||
class LocalLibraryBatchLookupRequest {
|
||||
final String? id;
|
||||
final String? isrc;
|
||||
final String trackName;
|
||||
final String artistName;
|
||||
|
||||
const LocalLibraryBatchLookupRequest({
|
||||
this.id,
|
||||
this.isrc,
|
||||
required this.trackName,
|
||||
required this.artistName,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1644,18 +1656,10 @@ class LibraryDatabase {
|
||||
|
||||
Future<LocalLibraryLookupIndex> getLookupIndex() async {
|
||||
final db = await database;
|
||||
final rows = await db.rawQuery(
|
||||
'SELECT id, file_path, isrc, match_key FROM library',
|
||||
);
|
||||
final rows = await db.rawQuery('SELECT isrc, match_key FROM library');
|
||||
final isrcs = <String>{};
|
||||
final matchKeys = <String>{};
|
||||
final filePathById = <String, String>{};
|
||||
for (final row in rows) {
|
||||
final id = row['id'] as String?;
|
||||
final filePath = row['file_path'] as String?;
|
||||
if (id != null && id.isNotEmpty && filePath != null) {
|
||||
filePathById[id] = filePath;
|
||||
}
|
||||
final isrc = row['isrc'] as String?;
|
||||
if (isrc != null && isrc.isNotEmpty) {
|
||||
isrcs.add(isrc);
|
||||
@@ -1668,7 +1672,6 @@ class LibraryDatabase {
|
||||
return LocalLibraryLookupIndex(
|
||||
isrcs: Set<String>.unmodifiable(isrcs),
|
||||
matchKeys: Set<String>.unmodifiable(matchKeys),
|
||||
filePathById: Map<String, String>.unmodifiable(filePathById),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user