From d1317bd9fe08a933a13df88ba692343cde549123 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 11 Feb 2021 20:10:56 +0800 Subject: ... --- BackEnd/Timeline/Services/DataManager.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'BackEnd/Timeline/Services/DataManager.cs') diff --git a/BackEnd/Timeline/Services/DataManager.cs b/BackEnd/Timeline/Services/DataManager.cs index f24bb59b..b697630c 100644 --- a/BackEnd/Timeline/Services/DataManager.cs +++ b/BackEnd/Timeline/Services/DataManager.cs @@ -22,20 +22,22 @@ 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); + public Task RetainEntry(byte[] data, bool saveDatabaseChange = true); /// /// 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); + public Task FreeEntry(string tag, bool saveDatabaseChange = true); /// /// Retrieve the entry with given tag. If not exist, returns null. @@ -57,7 +59,7 @@ namespace Timeline.Services _eTagGenerator = eTagGenerator; } - public async Task RetainEntry(byte[] data) + public async Task RetainEntry(byte[] data, bool saveDatabaseChange = true) { if (data == null) throw new ArgumentNullException(nameof(data)); @@ -80,11 +82,14 @@ namespace Timeline.Services { entity.Ref += 1; } - await _database.SaveChangesAsync(); + + if (saveDatabaseChange) + await _database.SaveChangesAsync(); + return tag; } - public async Task FreeEntry(string tag) + public async Task FreeEntry(string tag, bool saveDatabaseChange) { if (tag == null) throw new ArgumentNullException(nameof(tag)); @@ -101,7 +106,9 @@ namespace Timeline.Services { entity.Ref -= 1; } - await _database.SaveChangesAsync(); + + if (saveDatabaseChange) + await _database.SaveChangesAsync(); } } -- cgit v1.2.3