/// <summary> /// /// </summary> /// <returns></returns> public async Task <List <object> > Get() { //all of this code up here may not be neccessary //I need a way to speed up the application. var list = new List <object>(); using (var db = new AiApiDbContext()) { var tracks = db.RecentlyPlayed.ToList(); list.AddRange(tracks); } Thread kickThread = null; kickThread = new Thread(async() => { await KickoffSpotifySync(); AiThreadManager.RemoveThread(kickThread); }); AiThreadManager.AddThread(kickThread); if (list.Any()) { return(list); } return(new List <object>()); }
/// <summary> /// Deletes and rewrites the Top Artists and Top Tracks from spotify. Asynchnonously while also launching up two new threads. /// </summary> /// <param name="user">The user to get this information for.</param> public void SyncTopList(PrivateProfile user) { Thread artistThread = null; Thread trackThread = null; try { //the new thread for the artists objects artistThread = new Thread(async() => { await GetUsersTopArtistsShortTerm(user.Id); await GetUsersTopArtistsMeduimTerm(user.Id); await GetUsersTopArtistsLongTerm(user.Id); AiThreadManager.RemoveThread(artistThread); }); AiThreadManager.AddThread(artistThread); //the new thread for the track objects trackThread = new Thread(async() => { await GetUsersTopTracksShortTerm(user.Id); await GetUsersTopTracksMeduimTerm(user.Id); await GetUsersTopTracksLongTerm(user.Id); AiThreadManager.RemoveThread(trackThread); }); AiThreadManager.AddThread(trackThread); } catch (Exception ex) { Console.WriteLine(ex.InnerException); } finally { using (var db = new AiApiDbContext()) { db.TopSyncDates.Add(new sTopSync() { UserId = user.Id, SyncTop = SpotifyTopOptions.Artists }); db.TopSyncDates.Add(new sTopSync() { UserId = user.Id, SyncTop = SpotifyTopOptions.Tracks }); db.SaveChangesAsync(); } } }