From 3da17ba365c4b9f582abb4b2d1b9a542b0a00f32 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 20 Jan 2021 17:32:32 +0800 Subject: [PATCH] Add CancellationToken optional parameter to the Blogging module repository methods --- .../Volo/Blogging/Blogs/IBlogRepository.cs | 3 ++- .../Blogging/Comments/ICommentRepository.cs | 11 ++++---- .../Volo/Blogging/Posts/IPostRepository.cs | 9 ++++--- .../Volo/Blogging/Tagging/ITagRepository.cs | 8 +++--- .../Blogging/Blogs/EfCoreBlogRepository.cs | 5 ++-- .../Comments/EfCoreCommentRepository.cs | 17 +++++++------ .../Blogging/Posts/EfCorePostRepository.cs | 19 +++++++------- .../Blogging/Tagging/EfCoreTagRepository.cs | 16 ++++++------ .../Blogging/Blogs/MongoBlogRepository.cs | 5 ++-- .../Comments/MongoCommentRepository.cs | 25 ++++++++++--------- .../Blogging/Posts/MongoPostRepository.cs | 23 +++++++++-------- .../Blogging/Tagging/MongoTagRepository.cs | 18 ++++++------- .../Blogging/Users/MongoBlogUserRepository.cs | 6 ++--- 13 files changed, 86 insertions(+), 79 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs index ade8d1be0e..37dbf85ddd 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Blogs/IBlogRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -6,6 +7,6 @@ namespace Volo.Blogging.Blogs { public interface IBlogRepository : IBasicRepository { - Task FindByShortNameAsync(string shortName); + Task FindByShortNameAsync(string shortName, CancellationToken cancellationToken = default); } } diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs index 88ff91d516..65144cf5c2 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -7,14 +8,12 @@ namespace Volo.Blogging.Comments { public interface ICommentRepository : IBasicRepository { - Task> GetListOfPostAsync( - Guid postId - ); + Task> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default); - Task GetCommentCountOfPostAsync(Guid postId); + Task GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default); - Task> GetRepliesOfComment(Guid id); + Task> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default); - Task DeleteOfPost(Guid id); + Task DeleteOfPost(Guid id, CancellationToken cancellationToken = default); } } diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs index 9a49590015..b5446515bf 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -7,12 +8,12 @@ namespace Volo.Blogging.Posts { public interface IPostRepository : IBasicRepository { - Task> GetPostsByBlogId(Guid id); + Task> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default); - Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null); + Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default); - Task GetPostByUrl(Guid blogId, string url); + Task GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default); - Task> GetOrderedList(Guid blogId,bool descending = false); + Task> GetOrderedList(Guid blogId,bool descending = false, CancellationToken cancellationToken = default); } } diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs index 8c076c49d7..12aa0031ed 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs @@ -8,13 +8,13 @@ namespace Volo.Blogging.Tagging { public interface ITagRepository : IBasicRepository { - Task> GetListAsync(Guid blogId); + Task> GetListAsync(Guid blogId, CancellationToken cancellationToken = default); - Task GetByNameAsync(Guid blogId, string name); + Task GetByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default); - Task FindByNameAsync(Guid blogId, string name); + Task FindByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default); - Task> GetListAsync(IEnumerable ids); + Task> GetListAsync(IEnumerable ids, CancellationToken cancellationToken = default); Task DecreaseUsageCountOfTagsAsync(List id, CancellationToken cancellationToken = default); } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs index 564d45dc7a..d5397a66f0 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Blogs/EfCoreBlogRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -15,9 +16,9 @@ namespace Volo.Blogging.Blogs } - public async Task FindByShortNameAsync(string shortName) + public async Task FindByShortNameAsync(string shortName, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName); + return await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName, GetCancellationToken(cancellationToken)); } } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs index 6c28b521aa..801ef07825 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -16,29 +17,29 @@ namespace Volo.Blogging.Comments { } - public async Task> GetListOfPostAsync(Guid postId) + public async Task> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) .Where(a => a.PostId == postId) .OrderBy(a => a.CreationTime) - .ToListAsync(); + .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task GetCommentCountOfPostAsync(Guid postId) + public async Task GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) - .CountAsync(a => a.PostId == postId); + .CountAsync(a => a.PostId == postId, GetCancellationToken(cancellationToken)); } - public async Task> GetRepliesOfComment(Guid id) + public async Task> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) - .Where(a => a.RepliedCommentId == id).ToListAsync(); + .Where(a => a.RepliedCommentId == id).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task DeleteOfPost(Guid id) + public async Task DeleteOfPost(Guid id, CancellationToken cancellationToken = default) { - var recordsToDelete = (await GetDbSetAsync()).Where(pt => pt.PostId == id); + var recordsToDelete = await (await GetDbSetAsync()).Where(pt => pt.PostId == id).ToListAsync(GetCancellationToken(cancellationToken)); (await GetDbSetAsync()).RemoveRange(recordsToDelete); } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs index a5a84fd340..a676816dee 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Entities; @@ -18,12 +19,12 @@ namespace Volo.Blogging.Posts } - public async Task> GetPostsByBlogId(Guid id) + public async Task> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()).Where(p => p.BlogId == id).OrderByDescending(p=>p.CreationTime).ToListAsync(); + return await (await GetDbSetAsync()).Where(p => p.BlogId == id).OrderByDescending(p=>p.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) + public async Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default) { var query = (await GetDbSetAsync()).Where(p => blogId == p.BlogId && p.Url == url); @@ -32,12 +33,12 @@ namespace Volo.Blogging.Posts query = query.Where(p => excludingPostId != p.Id); } - return await query.AnyAsync(); + return await query.AnyAsync(GetCancellationToken(cancellationToken)); } - public async Task GetPostByUrl(Guid blogId, string url) + public async Task GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default) { - var post = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); + var post = await (await GetDbSetAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url, GetCancellationToken(cancellationToken)); if (post == null) { @@ -47,15 +48,15 @@ namespace Volo.Blogging.Posts return post; } - public async Task> GetOrderedList(Guid blogId,bool descending = false) + public async Task> GetOrderedList(Guid blogId,bool descending = false, CancellationToken cancellationToken = default) { if (!descending) { - return await (await GetDbSetAsync()).Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync(); + return await (await GetDbSetAsync()).Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); } else { - return await (await GetDbSetAsync()).Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync(); + return await (await GetDbSetAsync()).Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs index a92ae780da..0a33207374 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs @@ -17,24 +17,24 @@ namespace Volo.Blogging.Tagging { } - public async Task> GetListAsync(Guid blogId) + public async Task> GetListAsync(Guid blogId, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()).Where(t=>t.BlogId == blogId).ToListAsync(); + return await (await GetDbSetAsync()).Where(t=>t.BlogId == blogId).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task GetByNameAsync(Guid blogId, string name) + public async Task GetByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()).FirstAsync(t=> t.BlogId == blogId && t.Name == name); + return await (await GetDbSetAsync()).FirstAsync(t=> t.BlogId == blogId && t.Name == name, GetCancellationToken(cancellationToken)); } - public async Task FindByNameAsync(Guid blogId, string name) + public async Task FindByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()).FirstOrDefaultAsync(t => t.BlogId == blogId && t.Name == name); + return await (await GetDbSetAsync()).FirstOrDefaultAsync(t => t.BlogId == blogId && t.Name == name, GetCancellationToken(cancellationToken)); } - public async Task> GetListAsync(IEnumerable ids) + public async Task> GetListAsync(IEnumerable ids, CancellationToken cancellationToken = default) { - return await (await GetDbSetAsync()).Where(t => ids.Contains(t.Id)).ToListAsync(); + return await (await GetDbSetAsync()).Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken)); } public async Task DecreaseUsageCountOfTagsAsync(List ids, CancellationToken cancellationToken = default) diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs index 6025dfe3ca..0ef6b70a88 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Blogs/MongoBlogRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; @@ -13,9 +14,9 @@ namespace Volo.Blogging.Blogs { } - public async Task FindByShortNameAsync(string shortName) + public async Task FindByShortNameAsync(string shortName, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.ShortName == shortName); + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(p => p.ShortName == shortName, GetCancellationToken(cancellationToken)); } } } diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs index bbbe60345b..cfeb24475a 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Comments/MongoCommentRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; @@ -15,33 +16,33 @@ namespace Volo.Blogging.Comments { } - public async Task> GetListOfPostAsync(Guid postId) + public async Task> GetListOfPostAsync(Guid postId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()) + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) .Where(a => a.PostId == postId) .OrderBy(a => a.CreationTime) - .ToListAsync(); + .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task GetCommentCountOfPostAsync(Guid postId) + public async Task GetCommentCountOfPostAsync(Guid postId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()) - .CountAsync(a => a.PostId == postId); + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + .CountAsync(a => a.PostId == postId, GetCancellationToken(cancellationToken)); } - public async Task> GetRepliesOfComment(Guid id) + public async Task> GetRepliesOfComment(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()) - .Where(a => a.RepliedCommentId == id).ToListAsync(); + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) + .Where(a => a.RepliedCommentId == id).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task DeleteOfPost(Guid id) + public async Task DeleteOfPost(Guid id, CancellationToken cancellationToken = default) { - var recordsToDelete = (await GetMongoQueryableAsync()).Where(pt => pt.PostId == id); + var recordsToDelete = (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(pt => pt.PostId == id); foreach (var record in recordsToDelete) { - await DeleteAsync(record); + await DeleteAsync(record, cancellationToken: GetCancellationToken(cancellationToken)); } } } diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs index 27f4ad4348..ec40e8da4a 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; @@ -16,27 +17,27 @@ namespace Volo.Blogging.Posts { } - public async Task> GetPostsByBlogId(Guid id) + public async Task> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(); + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) + public async Task IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default) { - var query = (await GetMongoQueryableAsync()).Where(p => blogId == p.BlogId && p.Url == url); + var query = (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(p => blogId == p.BlogId && p.Url == url); if (excludingPostId != null) { query = query.Where(p => excludingPostId != p.Id); } - return await query.AnyAsync(); + return await query.AnyAsync(GetCancellationToken(cancellationToken)); } - public async Task GetPostByUrl(Guid blogId, string url) + public async Task GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default) { - var post = await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); + var post = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url, GetCancellationToken(cancellationToken)); if (post == null) { @@ -46,16 +47,16 @@ namespace Volo.Blogging.Posts return post; } - public async Task> GetOrderedList(Guid blogId, bool @descending = false) + public async Task> GetOrderedList(Guid blogId, bool @descending = false, CancellationToken cancellationToken = default) { - var query = (await GetMongoQueryableAsync()).Where(x => x.BlogId == blogId); + var query = (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(x => x.BlogId == blogId); if (!descending) { - return await query.OrderBy(x => x.CreationTime).ToListAsync(); + return await query.OrderBy(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); } - return await query.OrderByDescending(x => x.CreationTime).ToListAsync(); + return await query.OrderByDescending(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); } } } diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs index f0024b37d7..73999628ce 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Tagging/MongoTagRepository.cs @@ -18,29 +18,29 @@ namespace Volo.Blogging.Tagging { } - public async Task> GetListAsync(Guid blogId) + public async Task> GetListAsync(Guid blogId, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId).ToListAsync(); + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(t => t.BlogId == blogId).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task GetByNameAsync(Guid blogId, string name) + public async Task GetByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(); + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(GetCancellationToken(cancellationToken)); } - public async Task FindByNameAsync(Guid blogId, string name) + public async Task FindByNameAsync(Guid blogId, string name, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()).Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(); + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); } - public async Task> GetListAsync(IEnumerable ids) + public async Task> GetListAsync(IEnumerable ids, CancellationToken cancellationToken = default) { - return await (await GetMongoQueryableAsync()).Where(t => ids.Contains(t.Id)).ToListAsync(); + return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken)); } public async Task DecreaseUsageCountOfTagsAsync(List ids, CancellationToken cancellationToken = default) { - var tags = await (await GetMongoQueryableAsync()) + var tags = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) .Where(t => ids.Contains(t.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs index fdcf4d0097..c558799a86 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Users/MongoBlogUserRepository.cs @@ -15,16 +15,16 @@ namespace Volo.Blogging.Users { } - public async Task> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken) + public async Task> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken = default) { - var query = await GetMongoQueryableAsync(cancellationToken); + var query = await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)); if (!string.IsNullOrWhiteSpace(filter)) { query = query.Where(x => x.UserName.Contains(filter)); } - return await query.Take(maxCount).ToListAsync(cancellationToken); + return await query.Take(maxCount).ToListAsync(GetCancellationToken(cancellationToken)); } } }