-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced a new version of the LocalAnalytics system, that uses zip …
…based key value stores instead of real folders to increase performance
- Loading branch information
Showing
8 changed files
with
71 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
CsCore/PlainNetClassLib/src/Plugins/CsCore/com/csutil/logging/analytics/LocalAnalyticsV3.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using com.csutil.keyvaluestore; | ||
using Zio; | ||
|
||
namespace com.csutil.logging.analytics { | ||
|
||
public class LocalAnalyticsV3 : KeyValueStoreTypeAdapter<AppFlowEvent>, ILocalAnalytics { | ||
|
||
/// <summary> If the last 10 logs are missing if the app crashes this is probably ok, and not storing after every event increases performance </summary> | ||
private const int maxAllowedOpenChanges = 10; | ||
|
||
public IReadOnlyDictionary<string, KeyValueStoreTypeAdapter<AppFlowEvent>> categoryStores => _categoryStores; | ||
|
||
private readonly Dictionary<string, KeyValueStoreTypeAdapter<AppFlowEvent>> _categoryStores | ||
= new Dictionary<string, KeyValueStoreTypeAdapter<AppFlowEvent>>(); | ||
|
||
private readonly DirectoryEntry _dir; | ||
private readonly object _threadLock = new object(); | ||
|
||
public LocalAnalyticsV3(DirectoryEntry dirForEvents) | ||
: base(new ObservableKeyValueStore(ZipFileBasedKeyValueStore.New(dirForEvents.GetChild("AllEvents.zip"), maxAllowedOpenChanges))) { | ||
this._dir = dirForEvents; | ||
} | ||
|
||
public override async Task<AppFlowEvent> Set(string key, AppFlowEvent value) { | ||
var replacedEvent = await base.Set(key, value); | ||
await GetStoreForCategory(value.cat).Set(key, value); | ||
return replacedEvent; | ||
} | ||
|
||
public override async Task<bool> Remove(string key) { | ||
var res = await base.Remove(key); | ||
foreach (var s in _categoryStores.Values) { res &= await s.Remove(key); } | ||
return res; | ||
} | ||
|
||
public override async Task RemoveAll() { | ||
await base.RemoveAll(); | ||
foreach (var s in _categoryStores.Values) { await s.RemoveAll(); } | ||
} | ||
|
||
public KeyValueStoreTypeAdapter<AppFlowEvent> GetStoreForCategory(string catMethod) { | ||
lock (_threadLock) { | ||
if (_categoryStores.TryGetValue(catMethod, out var store)) { return store; } | ||
var createdStore = ZipFileBasedKeyValueStore.New(_dir.GetChild(catMethod + ".zip"), maxAllowedOpenChanges).GetTypeAdapter<AppFlowEvent>(); | ||
_categoryStores.Add(catMethod, createdStore); | ||
return createdStore; | ||
} | ||
} | ||
|
||
public void Dispose() { | ||
store.Dispose(); | ||
foreach (var s in categoryStores.Values) { s.store.Dispose(); } | ||
_categoryStores.Clear(); | ||
} | ||
|
||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
...PlainNetClassLib/src/Plugins/CsCore/com/csutil/logging/analytics/LocalAnalyticsV3.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters