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