From 343872c66adbfef9202a898cdcac7c1fe731cc61 Mon Sep 17 00:00:00 2001 From: Demis Bellot Date: Tue, 20 Aug 2024 15:48:58 +0800 Subject: [PATCH] Replace UpdatePostCommand with DB Lock --- .../App/PostSubscriptionsCommand.cs | 1 - .../App/UpdatePostCommand.cs | 25 ------------------- MyApp.ServiceInterface/QuestionServices.cs | 14 ++++++++++- MyApp.ServiceInterface/UserServices.cs | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) delete mode 100644 MyApp.ServiceInterface/App/UpdatePostCommand.cs diff --git a/MyApp.ServiceInterface/App/PostSubscriptionsCommand.cs b/MyApp.ServiceInterface/App/PostSubscriptionsCommand.cs index 21d779c..6518d19 100644 --- a/MyApp.ServiceInterface/App/PostSubscriptionsCommand.cs +++ b/MyApp.ServiceInterface/App/PostSubscriptionsCommand.cs @@ -12,7 +12,6 @@ public class PostSubscriptions public List? Unsubscriptions { get; set; } } - [Worker(Databases.App)] [Tag(Tags.Notifications)] public class PostSubscriptionsCommand(IDbConnection db) : SyncCommand diff --git a/MyApp.ServiceInterface/App/UpdatePostCommand.cs b/MyApp.ServiceInterface/App/UpdatePostCommand.cs deleted file mode 100644 index 9ba6062..0000000 --- a/MyApp.ServiceInterface/App/UpdatePostCommand.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Data; -using ServiceStack; -using ServiceStack.OrmLite; -using MyApp.ServiceModel; - -namespace MyApp.ServiceInterface.App; - -[Worker(Databases.App)] -[Tag(Tags.Questions)] -public class UpdatePostCommand(IDbConnection db) : SyncCommand -{ - protected override void Run(Post question) - { - db.UpdateOnly(() => new Post - { - Title = question.Title, - Tags = question.Tags, - Slug = question.Slug, - Summary = question.Summary, - ModifiedBy = question.ModifiedBy, - LastActivityDate = question.LastActivityDate, - LastEditDate = question.LastEditDate, - }, x => x.Id == question.Id); - } -} diff --git a/MyApp.ServiceInterface/QuestionServices.cs b/MyApp.ServiceInterface/QuestionServices.cs index e49e684..6d1b272 100644 --- a/MyApp.ServiceInterface/QuestionServices.cs +++ b/MyApp.ServiceInterface/QuestionServices.cs @@ -254,7 +254,19 @@ public async Task Any(UpdateQuestion request) question.LastActivityDate = DateTime.UtcNow; question.LastEditDate = question.LastActivityDate; - jobs.RunCommand(question); + lock (Workers.AppDb) + { + Db.UpdateOnly(() => new Post + { + Title = question.Title, + Tags = question.Tags, + Slug = question.Slug, + Summary = question.Summary, + ModifiedBy = question.ModifiedBy, + LastActivityDate = question.LastActivityDate, + LastEditDate = question.LastEditDate, + }, x => x.Id == question.Id); + } await questions.SaveQuestionEditAsync(question); return new UpdateQuestionResponse diff --git a/MyApp.ServiceInterface/UserServices.cs b/MyApp.ServiceInterface/UserServices.cs index 439120a..e3a3215 100644 --- a/MyApp.ServiceInterface/UserServices.cs +++ b/MyApp.ServiceInterface/UserServices.cs @@ -316,7 +316,7 @@ public async Task Any(ShareContent request) return HttpResult.Redirect($"/questions/{postId}/{post.Slug}" + (request.RefId.IndexOf('-') >= 0 ? $"#{request.RefId}" : "")); } - public async Task Any(FlagContent request) + public object Any(FlagContent request) { var postId = request.RefId.LeftPart('-').ToInt(); var post = Db.SingleById(postId);