Skip to content

Commit

Permalink
remove FirstOrDefaultAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed Apr 30, 2024
1 parent fa4b679 commit c11af02
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
5 changes: 1 addition & 4 deletions src/Moonglade.Core/PostFeature/GetPostBySlugQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ public async Task<PostEntity> Handle(GetPostBySlugQuery request, CancellationTok
var slugCheckSum = Helper.ComputeCheckSum($"{request.Slug.Slug}#{date:yyyyMMdd}");
var spec = new PostByChecksumSpec(slugCheckSum);

var pid = await repo.FirstOrDefaultAsync(spec, p => p.Id);
if (pid == Guid.Empty) return null;

var psm = await cache.GetOrCreateAsync(BlogCachePartition.Post.ToString(), $"{pid}", async entry =>
var psm = await cache.GetOrCreateAsync(BlogCachePartition.Post.ToString(), $"{slugCheckSum}", async entry =>
{
entry.SlidingExpiration = TimeSpan.FromMinutes(int.Parse(configuration["CacheSlidingExpirationMinutes:Post"]!));

Expand Down
4 changes: 0 additions & 4 deletions src/Moonglade.Data/MoongladeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public Task Clear(CancellationToken ct = default)
return dbContext.SaveChangesAsync(ct);
}

public Task<TResult> FirstOrDefaultAsync<TResult>(
ISpecification<T> spec, Expression<Func<T, TResult>> selector) =>
ApplySpecification(spec).AsNoTracking().Select(selector).FirstOrDefaultAsync();

public async Task<List<TResult>> SelectAsync<TResult>(Expression<Func<T, TResult>> selector, CancellationToken ct = default) =>
await dbContext.Set<T>().AsNoTracking().Select(selector).ToListAsync(cancellationToken: ct);

Expand Down

0 comments on commit c11af02

Please sign in to comment.