Skip to content

Commit

Permalink
Optimize CreateTodoListCommandValidator and UpdateTodoListCommandVali…
Browse files Browse the repository at this point in the history
…dator to improve performance by using AnyAsync
  • Loading branch information
tyfndmrl authored and jasontaylordev committed Nov 12, 2024
1 parent 900cbfd commit 945b1fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public CreateTodoListCommandValidator(IApplicationDbContext context)

public async Task<bool> BeUniqueTitle(string title, CancellationToken cancellationToken)
{
return await _context.TodoLists
.AllAsync(l => l.Title != title, cancellationToken);
return !await _context.TodoLists
.AnyAsync(l => l.Title == title, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public UpdateTodoListCommandValidator(IApplicationDbContext context)

public async Task<bool> BeUniqueTitle(UpdateTodoListCommand model, string title, CancellationToken cancellationToken)
{
return await _context.TodoLists
return !await _context.TodoLists
.Where(l => l.Id != model.Id)
.AllAsync(l => l.Title != title, cancellationToken);
.AnyAsync(l => l.Title == title, cancellationToken);
}
}

0 comments on commit 945b1fe

Please sign in to comment.