mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 00:59:28 +01:00
remove active sourceId subquery
This commit is contained in:
parent
fd800b0e12
commit
b9a094c1c4
@ -7,6 +7,7 @@ import '../../sources/models.dart';
|
||||
import '../hooks/use_on_source.dart';
|
||||
import '../hooks/use_paging_controller.dart';
|
||||
import '../state/database.dart';
|
||||
import '../state/source.dart';
|
||||
import 'list_items.dart';
|
||||
|
||||
const kPageSize = 60;
|
||||
@ -21,6 +22,7 @@ class AlbumsGrid extends HookConsumerWidget {
|
||||
getNextPageKey: (state) =>
|
||||
state.lastPageIsEmpty ? null : state.nextIntPageKey,
|
||||
fetchPage: (pageKey) => db.libraryDao.listAlbums(
|
||||
sourceId: ref.read(sourceIdProvider),
|
||||
limit: kPageSize,
|
||||
offset: (pageKey - 1) * kPageSize,
|
||||
),
|
||||
|
||||
@ -7,6 +7,7 @@ import '../../database/dao/library_dao.dart';
|
||||
import '../hooks/use_on_source.dart';
|
||||
import '../hooks/use_paging_controller.dart';
|
||||
import '../state/database.dart';
|
||||
import '../state/source.dart';
|
||||
import 'list_items.dart';
|
||||
|
||||
const kPageSize = 30;
|
||||
@ -21,6 +22,7 @@ class ArtistsList extends HookConsumerWidget {
|
||||
getNextPageKey: (state) =>
|
||||
state.lastPageIsEmpty ? null : state.nextIntPageKey,
|
||||
fetchPage: (pageKey) => db.libraryDao.listArtists(
|
||||
sourceId: ref.read(sourceIdProvider),
|
||||
limit: kPageSize,
|
||||
offset: (pageKey - 1) * kPageSize,
|
||||
),
|
||||
|
||||
@ -12,15 +12,13 @@ final activeSourceInitializer = StreamProvider<(int, SubsonicSource)>((
|
||||
|
||||
final activeSource = db.sourcesDao.activeSourceId().watchSingle();
|
||||
|
||||
await for (final source in activeSource) {
|
||||
final sourceId = source.read(db.sources.id)!;
|
||||
|
||||
await for (final sourceId in activeSource) {
|
||||
final subsonicSettings = await db.managers.subsonicSettings
|
||||
.filter((f) => f.sourceId.equals(sourceId))
|
||||
.getSingle();
|
||||
|
||||
yield (
|
||||
sourceId,
|
||||
sourceId!,
|
||||
SubsonicSource(
|
||||
SubsonicClient(
|
||||
http: SubtracksHttpClient(),
|
||||
|
||||
@ -13,14 +13,13 @@ class LibraryDao extends DatabaseAccessor<SubtracksDatabase>
|
||||
LibraryDao(super.db);
|
||||
|
||||
Future<List<models.Album>> listAlbums({
|
||||
required int sourceId,
|
||||
required int limit,
|
||||
required int offset,
|
||||
}) {
|
||||
final query = albums.select()
|
||||
..where(
|
||||
(f) => f.sourceId.equalsExp(
|
||||
subqueryExpression(db.sourcesDao.activeSourceId()),
|
||||
),
|
||||
(f) => f.sourceId.equals(sourceId),
|
||||
)
|
||||
..limit(limit, offset: offset);
|
||||
|
||||
@ -28,6 +27,7 @@ class LibraryDao extends DatabaseAccessor<SubtracksDatabase>
|
||||
}
|
||||
|
||||
Future<List<AristListItem>> listArtists({
|
||||
required int sourceId,
|
||||
required int limit,
|
||||
required int offset,
|
||||
}) async {
|
||||
@ -42,12 +42,8 @@ class LibraryDao extends DatabaseAccessor<SubtracksDatabase>
|
||||
])
|
||||
..addColumns([albumCount])
|
||||
..where(
|
||||
artists.sourceId.equalsExp(
|
||||
subqueryExpression(db.sourcesDao.activeSourceId()),
|
||||
) &
|
||||
albums.sourceId.equalsExp(
|
||||
subqueryExpression(db.sourcesDao.activeSourceId()),
|
||||
),
|
||||
artists.sourceId.equals(sourceId) &
|
||||
albums.sourceId.equals(sourceId),
|
||||
)
|
||||
..groupBy([artists.sourceId, artists.id])
|
||||
..orderBy([OrderingTerm.asc(artists.name)])
|
||||
|
||||
@ -9,10 +9,11 @@ class SourcesDao extends DatabaseAccessor<SubtracksDatabase>
|
||||
with _$SourcesDaoMixin {
|
||||
SourcesDao(super.db);
|
||||
|
||||
JoinedSelectStatement<Sources, Source> activeSourceId() {
|
||||
return selectOnly(sources)
|
||||
..addColumns([sources.id])
|
||||
..where(sources.isActive.equals(true));
|
||||
Selectable<int?> activeSourceId() {
|
||||
return (selectOnly(sources)
|
||||
..addColumns([sources.id])
|
||||
..where(sources.isActive.equals(true)))
|
||||
.map((row) => row.read(sources.id));
|
||||
}
|
||||
|
||||
Stream<List<(Source, SubsonicSetting)>> listSources() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user