Remove sourceId filtering from database queries - mix all sources

Co-authored-by: leinelissen <10154841+leinelissen@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-08 20:10:34 +00:00
co-authored by leinelissen
parent 6d7af425f4
commit 2eb7d1e622
4 changed files with 39 additions and 43 deletions
+3 -4
View File
@@ -10,13 +10,12 @@ export interface DownloadMetadata {
}
/**
* Get all downloads for a source
* Get all downloads (from all sources)
*/
export async function getAllDownloads(sourceId: string): Promise<Download[]> {
export async function getAllDownloads(): Promise<Download[]> {
const result = await db
.select()
.from(downloads)
.where(eq(downloads.sourceId, sourceId));
.from(downloads);
return result as Download[];
}
+3 -3
View File
@@ -10,11 +10,11 @@ import { eq } from 'drizzle-orm';
import { enrichDownload, type Download, type DownloadWithMetadata } from './db';
/**
* Get all downloads for a source
* Get all downloads (from all sources)
*/
export function useDownloads(sourceId: string) {
export function useDownloads() {
const { data, error } = useLiveQuery(
sourceId ? db.select().from(downloads).where(eq(downloads.sourceId, sourceId)) : null
db.select().from(downloads)
);
return useMemo(() => {
+7 -8
View File
@@ -14,8 +14,8 @@ import type { Album, AlbumTrack, MusicArtist, Playlist } from './types';
* ALBUMS
*/
export async function getAllAlbums(sourceId: string) {
const result = await db.select().from(albums).where(eq(albums.sourceId, sourceId));
export async function getAllAlbums() {
const result = await db.select().from(albums);
return result.map(album => enrichAlbum(album));
}
@@ -25,11 +25,10 @@ export async function getAlbum(id: string) {
return enrichAlbum(result[0]);
}
export async function getRecentAlbums(sourceId: string, limit: number = 50) {
export async function getRecentAlbums(limit: number = 50) {
const result = await db
.select()
.from(albums)
.where(eq(albums.sourceId, sourceId))
.orderBy(desc(albums.dateCreated))
.limit(limit);
return result.map(album => enrichAlbum(album));
@@ -114,8 +113,8 @@ export async function setSimilarAlbums(sourceId: string, albumId: string, simila
* ARTISTS
*/
export async function getAllArtists(sourceId: string) {
const result = await db.select().from(artists).where(eq(artists.sourceId, sourceId));
export async function getAllArtists() {
const result = await db.select().from(artists);
return result.map(artist => enrichArtist(artist));
}
@@ -256,8 +255,8 @@ export async function updateTrackCodec(trackId: string, codec: any) {
* PLAYLISTS
*/
export async function getAllPlaylists(sourceId: string) {
const result = await db.select().from(playlists).where(eq(playlists.sourceId, sourceId));
export async function getAllPlaylists() {
const result = await db.select().from(playlists);
return result.map(playlist => enrichPlaylist(playlist));
}
+26 -28
View File
@@ -11,17 +11,17 @@ import { artists } from '@/store/db/schema/artists';
import { tracks } from '@/store/db/schema/tracks';
import { playlists } from '@/store/db/schema/playlists';
import { playlistTracks } from '@/store/db/schema/playlist-tracks';
import { eq, desc, and, inArray } from 'drizzle-orm';
import { eq, desc, inArray } from 'drizzle-orm';
import { ALPHABET_LETTERS } from '@/CONSTANTS';
import type { SectionListData } from 'react-native';
import type { Album, AlbumTrack, MusicArtist, Playlist } from './types';
/**
* Get all albums for a source
* Get all albums (from all sources)
*/
export function useAlbums(sourceId: string) {
export function useAlbums() {
const { data, error } = useLiveQuery(
sourceId ? db.select().from(albums).where(eq(albums.sourceId, sourceId)) : null
db.select().from(albums)
);
return useMemo(() => {
@@ -48,13 +48,11 @@ export function useAlbums(sourceId: string) {
}
/**
* Get recent albums (sorted by date created)
* Get recent albums (sorted by date created, from all sources)
*/
export function useRecentAlbums(sourceId: string, amount: number = 24) {
export function useRecentAlbums(amount: number = 24) {
const { data, error } = useLiveQuery(
sourceId
? db.select().from(albums).where(eq(albums.sourceId, sourceId)).orderBy(desc(albums.dateCreated)).limit(amount)
: null
db.select().from(albums).orderBy(desc(albums.dateCreated)).limit(amount)
);
return useMemo(() => {
@@ -74,8 +72,8 @@ export function useRecentAlbums(sourceId: string, amount: number = 24) {
/**
* Get albums sorted by alphabet with sections
*/
export function useAlbumsByAlphabet(sourceId: string) {
const { albums: albumsMap, ids } = useAlbums(sourceId);
export function useAlbumsByAlphabet() {
const { albums: albumsMap, ids } = useAlbums();
return useMemo(() => {
// Sort by album artist
@@ -115,11 +113,11 @@ export function useAlbumsByAlphabet(sourceId: string) {
}
/**
* Get all artists for a source
* Get all artists (from all sources)
*/
export function useArtists(sourceId: string) {
export function useArtists() {
const { data, error } = useLiveQuery(
sourceId ? db.select().from(artists).where(eq(artists.sourceId, sourceId)) : null
db.select().from(artists)
);
return useMemo(() => {
@@ -148,8 +146,8 @@ export function useArtists(sourceId: string) {
/**
* Get artists sorted by alphabet with sections
*/
export function useArtistsByAlphabet(sourceId: string) {
const { artists: artistsMap } = useArtists(sourceId);
export function useArtistsByAlphabet() {
const { artists: artistsMap } = useArtists();
return useMemo(() => {
const artistsList = Object.values(artistsMap);
@@ -167,11 +165,11 @@ export function useArtistsByAlphabet(sourceId: string) {
}
/**
* Get all playlists for a source
* Get all playlists (from all sources)
*/
export function usePlaylists(sourceId: string) {
export function usePlaylists() {
const { data, error } = useLiveQuery(
sourceId ? db.select().from(playlists).where(eq(playlists.sourceId, sourceId)) : null
db.select().from(playlists)
);
return useMemo(() => {
@@ -200,10 +198,10 @@ export function usePlaylists(sourceId: string) {
/**
* Get tracks by album
*/
export function useTracksByAlbum(sourceId: string, albumId: string) {
export function useTracksByAlbum(albumId: string) {
const { data, error } = useLiveQuery(
sourceId && albumId
? db.select().from(tracks).where(and(eq(tracks.sourceId, sourceId), eq(tracks.albumId, albumId)))
albumId
? db.select().from(tracks).where(eq(tracks.albumId, albumId))
: null
);
@@ -224,10 +222,10 @@ export function useTracksByAlbum(sourceId: string, albumId: string) {
/**
* Get tracks by playlist
*/
export function useTracksByPlaylist(sourceId: string, playlistId: string) {
export function useTracksByPlaylist(playlistId: string) {
const { data: relations, error: relError } = useLiveQuery(
sourceId && playlistId
? db.select().from(playlistTracks).where(and(eq(playlistTracks.sourceId, sourceId), eq(playlistTracks.playlistId, playlistId)))
playlistId
? db.select().from(playlistTracks).where(eq(playlistTracks.playlistId, playlistId))
: null
);
@@ -258,11 +256,11 @@ export function useTracksByPlaylist(sourceId: string, playlistId: string) {
}
/**
* Get all tracks for a source
* Get all tracks (from all sources)
*/
export function useTracks(sourceId: string) {
export function useTracks() {
const { data, error } = useLiveQuery(
sourceId ? db.select().from(tracks).where(eq(tracks.sourceId, sourceId)) : null
db.select().from(tracks)
);
return useMemo(() => {