Skip to content

Commit

Permalink
Removes dependency of FlexLabs.EntityFrameworkCore.Upsert.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekspro committed Nov 18, 2023
1 parent c2785c0 commit f9cfe39
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void OnActivated(EventArgs e)
base.OnActivated(e);

ViewModel.OnNavigatedTo(StartParameter);
SongsViewModel.OnNavigatedTo(true, ViewModel.ChannelId);
SongsViewModel.OnNavigatedTo(true, StartParameter);
SchedulesEpisodesViewModel.OnNavigatedTo(StartParameter);
}

Expand Down
61 changes: 32 additions & 29 deletions Source/Pekspro.RadioStorm/CacheDatabase/CacheDatabaseManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Pekspro.RadioStorm.CacheDatabase;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace Pekspro.RadioStorm.CacheDatabase;

public sealed class CacheDatabaseManager
{
Expand Down Expand Up @@ -87,10 +89,7 @@ await Task.Run(async () =>
data.LatestUpdateTime = DateTimeProvider.OffsetNow;
await databaseContext.EpisodeData
.Upsert(data)
.RunAsync(cancellationToken)
.ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<EpisodeData>() { data }, cancellationToken: cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -140,7 +139,7 @@ await Task.Run(async () =>
}
await databaseContext.BulkInsertOrUpdateAsync(episodes, cancellationToken: cancellationToken);
await databaseContext.EpisodeListSyncStatusData.Upsert(p).RunAsync(cancellationToken);
await databaseContext.BulkInsertOrUpdateAsync(new List<EpisodeListSyncStatusData>() { p }, cancellationToken: cancellationToken).ConfigureAwait(false);
transaction.Commit();
};
Expand Down Expand Up @@ -415,7 +414,7 @@ await Task.Run(async () =>
using var databaseContext = CacheDatabaseContextFactory.Create();
data.LatestUpdateTime = DateTimeProvider.OffsetNow;
await databaseContext.ProgramData.Upsert(data).RunAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<ProgramData>() { data }, cancellationToken: cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false);
}
catch (TaskCanceledException)
Expand Down Expand Up @@ -456,8 +455,7 @@ await Task.Run(async () =>
await databaseContext.ProgramData.Where(a => true).BatchDeleteAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(programs, cancellationToken: cancellationToken).ConfigureAwait(false);
await databaseContext.ListSyncStatusData.Upsert(syncStats).RunAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<ListSyncStatusData>() { syncStats }, cancellationToken: cancellationToken).ConfigureAwait(false);
tran.Commit();
Expand Down Expand Up @@ -597,7 +595,7 @@ await Task.Run(async () =>
using var databaseContext = CacheDatabaseContextFactory.Create();
data.LatestUpdateTime = DateTimeProvider.OffsetNow;
await databaseContext.ChannelData.Upsert(data).RunAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<ChannelData>() { data }, cancellationToken: cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false);
}
catch (TaskCanceledException)
Expand Down Expand Up @@ -641,7 +639,7 @@ await Task.Run(async () =>
await databaseContext.ChannelData.Where(a => true).BatchDeleteAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(channels, cancellationToken: cancellationToken).ConfigureAwait(false);
await databaseContext.ListSyncStatusData.Upsert(syncStats).RunAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<ListSyncStatusData>() { syncStats }, cancellationToken: cancellationToken).ConfigureAwait(false);
tran.Commit();
Expand Down Expand Up @@ -737,11 +735,13 @@ await Task.Run(async () =>
await databaseContext.BulkInsertAsync(songs, cancellationToken: cancellationToken).ConfigureAwait(false);
await databaseContext.EpisodeSongListSyncStatusData.Upsert(new EpisodeSongListSyncStatusData()
{
EpisodeId = episodeId,
LatestUpdateTime = now
}).RunAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<EpisodeSongListSyncStatusData>() {
new EpisodeSongListSyncStatusData()
{
EpisodeId = episodeId,
LatestUpdateTime = now
}
}, cancellationToken: cancellationToken).ConfigureAwait(false);
tran.Commit();
Expand Down Expand Up @@ -876,11 +876,13 @@ await Task.Run(async () =>
await databaseContext.BulkInsertAsync(songs, cancellationToken: cancellationToken).ConfigureAwait(false);
await databaseContext.ChannelSongListSyncStatusData.Upsert(new ChannelSongListSyncStatusData()
{
ChannelId = channelId,
LatestUpdateTime = now
}).RunAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<ChannelSongListSyncStatusData>() {
new ChannelSongListSyncStatusData()
{
ChannelId = channelId,
LatestUpdateTime = now
}
}, cancellationToken: cancellationToken).ConfigureAwait(false);
tran.Commit();
Expand Down Expand Up @@ -1004,7 +1006,7 @@ await Task.Run(async () =>
status.LatestUpdateTime = DateTimeProvider.OffsetNow;
await databaseContext.ChannelStatusData.Upsert(status).RunAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<ChannelStatusData>() { status }, cancellationToken: cancellationToken).ConfigureAwait(false);
}, cancellationToken).ConfigureAwait(false);
}
catch (TaskCanceledException)
Expand Down Expand Up @@ -1142,13 +1144,14 @@ await Task.Run(async () =>
await databaseContext.BulkInsertAsync(episodes, cancellationToken: cancellationToken).ConfigureAwait(false);
await databaseContext.ScheduledEpisodeListSyncStatusData.Upsert(new ScheduledEpisodeListSyncStatusData()
{
ChannelId = channelId,
Date = date,
LatestUpdateTime = now
}
).RunAsync(cancellationToken).ConfigureAwait(false);
await databaseContext.BulkInsertOrUpdateAsync(new List<ScheduledEpisodeListSyncStatusData>() {
new ScheduledEpisodeListSyncStatusData()
{
ChannelId = channelId,
Date = date,
LatestUpdateTime = now
}
}, cancellationToken: cancellationToken).ConfigureAwait(false);
tran.Commit();
Expand Down
1 change: 0 additions & 1 deletion Source/Pekspro.RadioStorm/Pekspro.RadioStorm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="EFCore.BulkExtensions" Version="6.6.2" />
<PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="6.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.11">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit f9cfe39

Please sign in to comment.