From 780d19611549182e7f8cbebdb05498f33a8e1de0 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 13 Feb 2021 22:27:29 +0800 Subject: fix: No longer able to not save change in data manager. --- BackEnd/Timeline/Services/DataManager.cs | 16 ++++++---------- .../Migration/TimelinePostContentToDataMigration.cs | 2 +- BackEnd/Timeline/Services/TimelinePostService.cs | 4 ++-- 3 files changed, 9 insertions(+), 13 deletions(-) (limited to 'BackEnd') diff --git a/BackEnd/Timeline/Services/DataManager.cs b/BackEnd/Timeline/Services/DataManager.cs index b697630c..b43b80f9 100644 --- a/BackEnd/Timeline/Services/DataManager.cs +++ b/BackEnd/Timeline/Services/DataManager.cs @@ -22,22 +22,20 @@ namespace Timeline.Services /// increases its ref count and returns a tag to the entry. /// /// The data. Can't be null. - /// If true save database change. Otherwise it does not save database change. /// The tag of the created entry. /// Thrown when is null. - public Task RetainEntry(byte[] data, bool saveDatabaseChange = true); + public Task RetainEntry(byte[] data); /// /// Decrease the the ref count of the entry. /// Remove it if ref count is zero. /// /// The tag of the entry. - /// If true save database change. Otherwise it does not save database change. /// Thrown when is null. /// /// It's no-op if entry with tag does not exist. /// - public Task FreeEntry(string tag, bool saveDatabaseChange = true); + public Task FreeEntry(string tag); /// /// Retrieve the entry with given tag. If not exist, returns null. @@ -59,7 +57,7 @@ namespace Timeline.Services _eTagGenerator = eTagGenerator; } - public async Task RetainEntry(byte[] data, bool saveDatabaseChange = true) + public async Task RetainEntry(byte[] data) { if (data == null) throw new ArgumentNullException(nameof(data)); @@ -83,13 +81,12 @@ namespace Timeline.Services entity.Ref += 1; } - if (saveDatabaseChange) - await _database.SaveChangesAsync(); + await _database.SaveChangesAsync(); return tag; } - public async Task FreeEntry(string tag, bool saveDatabaseChange) + public async Task FreeEntry(string tag) { if (tag == null) throw new ArgumentNullException(nameof(tag)); @@ -107,8 +104,7 @@ namespace Timeline.Services entity.Ref -= 1; } - if (saveDatabaseChange) - await _database.SaveChangesAsync(); + await _database.SaveChangesAsync(); } } diff --git a/BackEnd/Timeline/Services/Migration/TimelinePostContentToDataMigration.cs b/BackEnd/Timeline/Services/Migration/TimelinePostContentToDataMigration.cs index de2e2183..bb7bf606 100644 --- a/BackEnd/Timeline/Services/Migration/TimelinePostContentToDataMigration.cs +++ b/BackEnd/Timeline/Services/Migration/TimelinePostContentToDataMigration.cs @@ -33,7 +33,7 @@ namespace Timeline.Services.Migration { if (postEntity.ContentType == "text") { - var tag = await _dataManager.RetainEntry(Encoding.UTF8.GetBytes(postEntity.Content), false); + var tag = await _dataManager.RetainEntry(Encoding.UTF8.GetBytes(postEntity.Content)); database.TimelinePostData.Add(new TimelinePostDataEntity { DataTag = tag, diff --git a/BackEnd/Timeline/Services/TimelinePostService.cs b/BackEnd/Timeline/Services/TimelinePostService.cs index 62bc43cc..88a93710 100644 --- a/BackEnd/Timeline/Services/TimelinePostService.cs +++ b/BackEnd/Timeline/Services/TimelinePostService.cs @@ -361,7 +361,7 @@ namespace Timeline.Services { var data = request.DataList[index]; - var tag = await _dataManager.RetainEntry(data.Data, false); + var tag = await _dataManager.RetainEntry(data.Data); _database.TimelinePostData.Add(new TimelinePostDataEntity { @@ -436,7 +436,7 @@ namespace Timeline.Services foreach (var dataEntity in dataEntities) { - await _dataManager.FreeEntry(dataEntity.DataTag, false); + await _dataManager.FreeEntry(dataEntity.DataTag); } _database.TimelinePostData.RemoveRange(dataEntities); -- cgit v1.2.3