コード例 #1
0
        public override async Task <Artist> LastPlayedArtist(int userId)
        {
            var sql = @"SELECT a.*
                        FROM `usertrack` ut
                        join `track` t on (ut.trackId = t.id)
                        join `releasemedia` rm on (t.releaseMediaId = rm.id)
                        join `release` r on (rm.releaseId = r.id)
                        join `artist` a on (r.artistId = a.id)
                        where ut.userId = {0}
                        ORDER by ut.lastPlayed desc
                        LIMIT 1";

            return(await Artists.FromSqlRaw(sql, userId).FirstOrDefaultAsync());
        }
コード例 #2
0
        public override async Task <SortedDictionary <int, int> > RandomArtistIds(int userId, int randomLimit, bool doOnlyFavorites = false, bool doOnlyRated = false)
        {
            var sql = @"SELECT a.id
                        FROM `artist` a
                        WHERE(a.id NOT IN(select artistId FROM `userartist` where userId = {1} and isDisliked = 1))
                        OR(a.id IN(select artistId FROM `userartist` where userId = {1} and isFavorite = 1)
                        AND {2} = 1)
                        order BY RIGHT(HEX((1 << 24) * (1 + RAND())), 6)
                        LIMIT 0, {0}";
            var ids = await Artists.FromSqlRaw(sql, randomLimit, userId, doOnlyFavorites? "1" : "0").Select(x => x.Id).ToListAsync();

            var dict = ids.Select((id, i) => new { key = i, value = id }).ToDictionary(x => x.key, x => x.value);

            return(new SortedDictionary <int, int>(dict));
        }