Skip to content

Commit

Permalink
core: migrate tracks.json to database
Browse files Browse the repository at this point in the history
- and 10000000x improve performance of `_addTheseTracksToAlbumGenreArtistEtc()`, this can be noticed while (editing tags/reindexing tracks/playing external files)
  • Loading branch information
MSOB7YY committed Nov 5, 2024
1 parent d842499 commit 1bd49e4
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 97 deletions.
6 changes: 3 additions & 3 deletions lib/class/split_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import 'package:namida/core/constants.dart';
import 'package:namida/core/extensions.dart';

class SplitArtistGenreConfigsWrapper {
final String path;
final String dbPath;
final ArtistsSplitConfig artistsConfig;
final GenresSplitConfig genresConfig;
final GeneralSplitConfig generalConfig;

const SplitArtistGenreConfigsWrapper({
required this.path,
required this.dbPath,
required this.artistsConfig,
required this.genresConfig,
required this.generalConfig,
});

factory SplitArtistGenreConfigsWrapper.settings() {
return SplitArtistGenreConfigsWrapper(
path: AppPaths.TRACKS,
dbPath: AppPaths.TRACKS_DB_INFO.file.path,
artistsConfig: ArtistsSplitConfig.settings(),
genresConfig: GenresSplitConfig.settings(),
generalConfig: GeneralSplitConfig(),
Expand Down
6 changes: 3 additions & 3 deletions lib/class/track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ class TrackExtended {
}

factory TrackExtended.fromJson(
String path,
Map<String, dynamic> json, {
required ArtistsSplitConfig artistsSplitConfig,
required GenresSplitConfig genresSplitConfig,
Expand Down Expand Up @@ -349,7 +350,7 @@ class TrackExtended {
size: json['size'] ?? 0,
dateAdded: json['dateAdded'] ?? 0,
dateModified: json['dateModified'] ?? 0,
path: json['path'] ?? '',
path: path,
comment: json['comment'] ?? '',
description: json['description'] ?? '',
synopsis: json['synopsis'] ?? '',
Expand All @@ -372,7 +373,7 @@ class TrackExtended {
);
}

Map<String, dynamic> toJson() {
Map<String, dynamic> toJsonWithoutPath() {
return {
if (title.isNotEmpty) 'title': title,
if (originalArtist.isNotEmpty) 'originalArtist': originalArtist,
Expand All @@ -387,7 +388,6 @@ class TrackExtended {
if (size > 0) 'size': size,
if (dateAdded > 0) 'dateAdded': dateAdded,
if (dateModified > 0) 'dateModified': dateModified,
if (path.isNotEmpty) 'path': path,
if (comment.isNotEmpty) 'comment': comment,
if (description.isNotEmpty) 'description': description,
if (synopsis.isNotEmpty) 'synopsis': synopsis,
Expand Down
3 changes: 2 additions & 1 deletion lib/controller/backup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class BackupController {
final diff = DateTime.now().difference(lastModified).abs().inDays;
if (diff > interval) {
final itemsToBackup = [
AppPaths.TRACKS,
AppPaths.TRACKS_OLD,
AppPaths.TRACKS_DB_INFO.file.path,
AppPaths.TRACKS_STATS_OLD,
AppPaths.TRACKS_STATS_DB_INFO.file.path,
AppPaths.TOTAL_LISTEN_TIME,
Expand Down
Loading

0 comments on commit 1bd49e4

Please sign in to comment.