public override async Task <Release> LastPlayedRelease(int userId) { var sql = @"SELECT r.* 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) WHERE ut.userId = {0} ORDER by ut.lastPlayed desc LIMIT 1"; return(await Releases.FromSqlRaw(sql, userId) .Include(x => x.Artist) .FirstOrDefaultAsync()); }
public override async Task <SortedDictionary <int, int> > RandomReleaseIds(int userId, int randomLimit, bool doOnlyFavorites = false, bool doOnlyRated = false) { var sql = @"SELECT r.id FROM `release` r WHERE (r.id NOT IN (select releaseId FROM `userrelease` where userId = {1} and isDisliked = 1)) OR (r.id IN (select releaseId FROM `userrelease` where userId = {1} and isFavorite = 1) AND {2} = 1) ORDER BY RIGHT( HEX( (1<<24) * (1+RAND()) ), 6) LIMIT 0, {0}"; var ids = await Releases.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)); }