adding to repos, speeding up hopefully
This commit is contained in:
parent
2247498c70
commit
c646e4ea27
@ -70,6 +70,8 @@ namespace Selector.Model
|
||||
modelBuilder.Entity<UserScrobble>()
|
||||
.Property(s => s.ArtistName)
|
||||
.UseCollation("case_insensitive");
|
||||
//modelBuilder.Entity<UserScrobble>()
|
||||
// .HasIndex(x => new { x.UserId, x.ArtistName, x.TrackName });
|
||||
|
||||
modelBuilder.Entity<TrackLastfmSpotifyMapping>().HasKey(s => s.SpotifyUri);
|
||||
modelBuilder.Entity<TrackLastfmSpotifyMapping>()
|
||||
@ -102,6 +104,8 @@ namespace Selector.Model
|
||||
modelBuilder.Entity<SpotifyListen>()
|
||||
.Property(s => s.ArtistName)
|
||||
.UseCollation("case_insensitive");
|
||||
//modelBuilder.Entity<SpotifyListen>()
|
||||
// .HasIndex(x => new { x.UserId, x.ArtistName, x.TrackName });
|
||||
|
||||
SeedData.Seed(modelBuilder);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ namespace Selector.Model
|
||||
{
|
||||
public interface IListenRepository
|
||||
{
|
||||
IEnumerable<IListen> GetAll(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null);
|
||||
IEnumerable<IListen> GetAll(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null, bool tracking = true, bool orderTime = false);
|
||||
int Count(string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,8 @@ public class MetaListenRepository: IListenRepository
|
||||
albumName: albumName,
|
||||
artistName: artistName,
|
||||
from: from,
|
||||
to:to).Count();
|
||||
to:to,
|
||||
tracking: false).Count();
|
||||
|
||||
public IEnumerable<IListen> GetAll(
|
||||
string includes = null,
|
||||
@ -38,7 +39,9 @@ public class MetaListenRepository: IListenRepository
|
||||
string albumName = null,
|
||||
string artistName = null,
|
||||
DateTime? from = null,
|
||||
DateTime? to = null)
|
||||
DateTime? to = null,
|
||||
bool tracking = true,
|
||||
bool orderTime = false)
|
||||
{
|
||||
var scrobbles = scrobbleRepository.GetAll(
|
||||
include: includes,
|
||||
@ -48,9 +51,9 @@ public class MetaListenRepository: IListenRepository
|
||||
albumName: albumName,
|
||||
artistName: artistName,
|
||||
from: from,
|
||||
to: to)
|
||||
.OrderBy(x => x.Timestamp)
|
||||
.ToArray();
|
||||
to: to,
|
||||
tracking: tracking,
|
||||
orderTime: true).ToArray();
|
||||
|
||||
var spotListens = spotifyRepository.GetAll(
|
||||
include: includes,
|
||||
@ -60,10 +63,9 @@ public class MetaListenRepository: IListenRepository
|
||||
albumName: albumName,
|
||||
artistName: artistName,
|
||||
from: from,
|
||||
to: scrobbles.FirstOrDefault()?.Timestamp)
|
||||
.OrderBy(x => x.Timestamp)
|
||||
.ToArray();
|
||||
|
||||
to: scrobbles.LastOrDefault()?.Timestamp,
|
||||
tracking: tracking,
|
||||
orderTime: orderTime);
|
||||
|
||||
return spotListens.Concat(scrobbles);
|
||||
}
|
||||
|
@ -39,10 +39,15 @@ namespace Selector.Model
|
||||
return listens.FirstOrDefault();
|
||||
}
|
||||
|
||||
private IQueryable<SpotifyListen> GetAllQueryable(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null)
|
||||
private IQueryable<SpotifyListen> GetAllQueryable(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null, bool tracking = true, bool orderTime = false)
|
||||
{
|
||||
var listens = db.SpotifyListen.AsQueryable();
|
||||
|
||||
if (!tracking)
|
||||
{
|
||||
listens = listens.AsNoTracking();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(include))
|
||||
{
|
||||
listens = listens.Include(include);
|
||||
@ -92,11 +97,16 @@ namespace Selector.Model
|
||||
listens = listens.Where(u => u.Timestamp < to.Value);
|
||||
}
|
||||
|
||||
if (orderTime)
|
||||
{
|
||||
listens = listens.OrderBy(x => x.Timestamp);
|
||||
}
|
||||
|
||||
return listens;
|
||||
}
|
||||
|
||||
public IEnumerable<IListen> GetAll(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null)
|
||||
=> GetAllQueryable(include: include, userId: userId, username: username, trackName: trackName, albumName: albumName, artistName: artistName, from: from, to: to).AsEnumerable();
|
||||
public IEnumerable<IListen> GetAll(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null, bool tracking = true, bool orderTime = false)
|
||||
=> GetAllQueryable(include: include, userId: userId, username: username, trackName: trackName, albumName: albumName, artistName: artistName, from: from, to: to, tracking: tracking, orderTime: orderTime).AsEnumerable();
|
||||
|
||||
public void Remove(DateTime key)
|
||||
{
|
||||
@ -124,6 +134,6 @@ namespace Selector.Model
|
||||
}
|
||||
|
||||
public int Count(string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null)
|
||||
=> GetAllQueryable(userId: userId, username: username, trackName: trackName, albumName: albumName, artistName: artistName, from: from, to: to).Count();
|
||||
=> GetAllQueryable(userId: userId, username: username, trackName: trackName, albumName: albumName, artistName: artistName, from: from, to: to, tracking: false).Count();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace Selector.Cache
|
||||
|
||||
var userScrobbleCount = ScrobbleRepository.Count(username: username);
|
||||
|
||||
var artistScrobbles = ScrobbleRepository.GetAll(username: username, artistName: artist).ToArray();
|
||||
var artistScrobbles = ScrobbleRepository.GetAll(username: username, artistName: artist, tracking: false, orderTime: true).ToArray();
|
||||
var albumScrobbles = artistScrobbles.Where(
|
||||
s => s.AlbumName.Equals(album, StringComparison.CurrentCultureIgnoreCase)).ToArray();
|
||||
var trackScrobbles = artistScrobbles.Where(
|
||||
|
@ -39,10 +39,15 @@ namespace Selector.Model
|
||||
return scrobbles.FirstOrDefault();
|
||||
}
|
||||
|
||||
private IQueryable<UserScrobble> GetAllQueryable(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null)
|
||||
private IQueryable<UserScrobble> GetAllQueryable(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null, bool tracking = true, bool orderTime = false)
|
||||
{
|
||||
var scrobbles = db.Scrobble.AsQueryable();
|
||||
|
||||
if (!tracking)
|
||||
{
|
||||
scrobbles = scrobbles.AsNoTracking();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(include))
|
||||
{
|
||||
scrobbles = scrobbles.Include(include);
|
||||
@ -92,11 +97,16 @@ namespace Selector.Model
|
||||
scrobbles = scrobbles.Where(u => u.Timestamp < to.Value);
|
||||
}
|
||||
|
||||
if (orderTime)
|
||||
{
|
||||
scrobbles = scrobbles.OrderBy(x => x.Timestamp);
|
||||
}
|
||||
|
||||
return scrobbles;
|
||||
}
|
||||
|
||||
public IEnumerable<IListen> GetAll(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null)
|
||||
=> GetAllQueryable(include: include, userId: userId, username: username, trackName: trackName, albumName: albumName, artistName: artistName, from: from, to: to).AsEnumerable();
|
||||
public IEnumerable<IListen> GetAll(string include = null, string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null, bool tracking = true, bool orderTime = false)
|
||||
=> GetAllQueryable(include: include, userId: userId, username: username, trackName: trackName, albumName: albumName, artistName: artistName, from: from, to: to, tracking: tracking, orderTime: orderTime).AsEnumerable();
|
||||
|
||||
public void Remove(int key)
|
||||
{
|
||||
@ -124,6 +134,6 @@ namespace Selector.Model
|
||||
}
|
||||
|
||||
public int Count(string userId = null, string username = null, string trackName = null, string albumName = null, string artistName = null, DateTime? from = null, DateTime? to = null)
|
||||
=> GetAllQueryable(userId: userId, username: username, trackName: trackName, albumName: albumName, artistName: artistName, from: from, to: to).Count();
|
||||
=> GetAllQueryable(userId: userId, username: username, trackName: trackName, albumName: albumName, artistName: artistName, from: from, to: to, tracking: false).Count();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user