Skip to content

Commit 7713d8b

Browse files
committed
refactor: Smaller code improvements
1 parent 7d3b741 commit 7713d8b

File tree

9 files changed

+23
-21
lines changed

9 files changed

+23
-21
lines changed

src/LinkDotNet.Blog.Infrastructure/PagedList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace LinkDotNet.Blog.Infrastructure;
99
[DebuggerDisplay("PagedList<{typeof(T).Name}>, Count = {Count}")]
1010
public sealed class PagedList<T> : IPagedList<T>
1111
{
12-
public static readonly PagedList<T> Empty = new(Enumerable.Empty<T>(), 0, 0, 0);
12+
public static readonly PagedList<T> Empty = new([], 0, 0, 0);
1313

1414
private readonly IReadOnlyList<T> subset;
1515
private readonly int totalPages;

src/LinkDotNet.Blog.Infrastructure/Persistence/CachedRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public async ValueTask DeleteAsync(string id)
7070
}
7171
}
7272

73-
public async ValueTask DeleteBulkAsync(IEnumerable<string> ids) => await repository.DeleteBulkAsync(ids);
73+
public async ValueTask DeleteBulkAsync(IReadOnlyCollection<string> ids) => await repository.DeleteBulkAsync(ids);
7474

75-
public async ValueTask StoreBulkAsync(IEnumerable<T> records) => await repository.StoreBulkAsync(records);
75+
public async ValueTask StoreBulkAsync(IReadOnlyCollection<T> records) => await repository.StoreBulkAsync(records);
7676
}

src/LinkDotNet.Blog.Infrastructure/Persistence/IRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
3434

3535
ValueTask DeleteAsync(string id);
3636

37-
ValueTask DeleteBulkAsync(IEnumerable<string> ids);
37+
ValueTask DeleteBulkAsync(IReadOnlyCollection<string> ids);
3838

39-
ValueTask StoreBulkAsync(IEnumerable<TEntity> records);
39+
ValueTask StoreBulkAsync(IReadOnlyCollection<TEntity> records);
4040
}

src/LinkDotNet.Blog.Infrastructure/Persistence/InMemory/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public ValueTask DeleteAsync(string id)
8686
return ValueTask.CompletedTask;
8787
}
8888

89-
public ValueTask DeleteBulkAsync(IEnumerable<string> ids)
89+
public ValueTask DeleteBulkAsync(IReadOnlyCollection<string> ids)
9090
{
9191
ArgumentNullException.ThrowIfNull(ids);
9292

@@ -99,7 +99,7 @@ public ValueTask DeleteBulkAsync(IEnumerable<string> ids)
9999
return ValueTask.CompletedTask;
100100
}
101101

102-
public ValueTask StoreBulkAsync(IEnumerable<TEntity> records)
102+
public ValueTask StoreBulkAsync(IReadOnlyCollection<TEntity> records)
103103
{
104104
entities.AddRange(records);
105105
return ValueTask.CompletedTask;

src/LinkDotNet.Blog.Infrastructure/Persistence/MongoDB/Repository.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,17 @@ public async ValueTask DeleteAsync(string id)
9696
await Collection.DeleteOneAsync(filter);
9797
}
9898

99-
public async ValueTask DeleteBulkAsync(IEnumerable<string> ids)
99+
public async ValueTask DeleteBulkAsync(IReadOnlyCollection<string> ids)
100100
{
101101
var filter = Builders<TEntity>.Filter.In(doc => doc.Id, ids);
102102
await Collection.DeleteManyAsync(filter);
103103
}
104104

105-
public async ValueTask StoreBulkAsync(IEnumerable<TEntity> records)
105+
public async ValueTask StoreBulkAsync(IReadOnlyCollection<TEntity> records)
106106
{
107-
if (records.Any())
107+
ArgumentNullException.ThrowIfNull(records);
108+
109+
if (records.Count != 0)
108110
{
109111
await Collection.InsertManyAsync(records);
110112
}

src/LinkDotNet.Blog.Infrastructure/Persistence/RavenDb/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public async ValueTask DeleteAsync(string id)
9090
await session.SaveChangesAsync();
9191
}
9292

93-
public async ValueTask DeleteBulkAsync(IEnumerable<string> ids)
93+
public async ValueTask DeleteBulkAsync(IReadOnlyCollection<string> ids)
9494
{
9595
ArgumentNullException.ThrowIfNull(ids);
9696

@@ -103,7 +103,7 @@ public async ValueTask DeleteBulkAsync(IEnumerable<string> ids)
103103
await session.SaveChangesAsync();
104104
}
105105

106-
public async ValueTask StoreBulkAsync(IEnumerable<TEntity> records)
106+
public async ValueTask StoreBulkAsync(IReadOnlyCollection<TEntity> records)
107107
{
108108
ArgumentNullException.ThrowIfNull(records);
109109

src/LinkDotNet.Blog.Infrastructure/Persistence/Sql/Repository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ public async ValueTask DeleteAsync(string id)
107107
}
108108
}
109109

110-
public async ValueTask DeleteBulkAsync(IEnumerable<string> ids)
110+
public async ValueTask DeleteBulkAsync(IReadOnlyCollection<string> ids)
111111
{
112112
var blogDbContext = await dbContextFactory.CreateDbContextAsync();
113113
var strategy = blogDbContext.Database.CreateExecutionStrategy();
114114

115-
await strategy.ExecuteAsync(async () => await DeleteBulkAsyncInBatchesAsync());
115+
await strategy.ExecuteAsync(DeleteBulkAsyncInBatchesAsync);
116116

117117
async Task DeleteBulkAsyncInBatchesAsync()
118118
{
@@ -137,14 +137,14 @@ await blogDbContext.Set<TEntity>()
137137
}
138138
}
139139

140-
public async ValueTask StoreBulkAsync(IEnumerable<TEntity> records)
140+
public async ValueTask StoreBulkAsync(IReadOnlyCollection<TEntity> records)
141141
{
142142
ArgumentNullException.ThrowIfNull(records);
143143

144144
var blogDbContext = await dbContextFactory.CreateDbContextAsync();
145145
var strategy = blogDbContext.Database.CreateExecutionStrategy();
146146

147-
await strategy.ExecuteAsync(async () => await StoreBulkAsyncInBatchesAsync());
147+
await strategy.ExecuteAsync(StoreBulkAsyncInBatchesAsync);
148148

149149
async Task StoreBulkAsyncInBatchesAsync()
150150
{

src/LinkDotNet.Blog.Web/Features/TransformBlogPostRecordsService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ private async Task TransformRecordsAsync()
9999

100100
var mergedRecords = MergeRecords(newBlogPostRecords, oldBlogPostRecords);
101101

102-
await blogPostRecordRepository.DeleteBulkAsync(oldBlogPostRecords.Select(o => o.Id));
103-
await blogPostRecordRepository.StoreBulkAsync(mergedRecords);
102+
await blogPostRecordRepository.DeleteBulkAsync(oldBlogPostRecords.Select(o => o.Id).ToArray());
103+
await blogPostRecordRepository.StoreBulkAsync(mergedRecords.ToArray());
104104

105105
LogDeletingUserRecords(userRecords.Count);
106-
await userRecordRepository.DeleteBulkAsync(userRecords.Select(u => u.Id));
106+
await userRecordRepository.DeleteBulkAsync(userRecords.Select(u => u.Id).ToArray());
107107
LogDeletedUserRecords();
108108
}
109109

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Archive/ArchivePageTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProject
128128

129129
public ValueTask DeleteAsync(string id) => throw new NotImplementedException();
130130

131-
public ValueTask DeleteBulkAsync(IEnumerable<string> ids) => throw new NotImplementedException();
131+
public ValueTask DeleteBulkAsync(IReadOnlyCollection<string> ids) => throw new NotImplementedException();
132132

133-
public ValueTask StoreBulkAsync(IEnumerable<BlogPost> records) => throw new NotImplementedException();
133+
public ValueTask StoreBulkAsync(IReadOnlyCollection<BlogPost> records) => throw new NotImplementedException();
134134
}
135135
}

0 commit comments

Comments
 (0)