Skip to content

Commit

Permalink
IAnalyzer gets both the new database and the old database as argume…
Browse files Browse the repository at this point in the history
…nts. This allows for looking up the previous state of entities for retractions
  • Loading branch information
halgari committed Aug 22, 2024
1 parent 5fe612d commit 733fcfb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

### 0.9.80 - 22/08/2024
* `IAnalyzer` gets both the new database and the old database as arguments. This allows for looking up the previous state of entities for retractions

### 0.9.79 - 19/08/2024
* Fix a bug with `Tuple<T1, T2, T3>` attributes when the first member is a reference type. This caused temporary IDs to not
be resolved correctly when the temporary ID was resolved
Expand Down
1 change: 1 addition & 0 deletions NexusMods.MnemonicDB.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=datom/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=datoms/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion src/NexusMods.MnemonicDB.Abstractions/IAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IAnalyzer
/// <summary>
/// Analyze the database and produce a result.
/// </summary>
public object Analyze(IDb db);
public object Analyze(IDb? dbOld, IDb dbNew);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/NexusMods.MnemonicDB/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public Connection(ILogger<Connection> logger, IDatomStore store, IServiceProvide
/// </summary>
private IObservable<Db> ProcessUpdate(IObservable<IDb> dbStream)
{
TxId? prev = null;
IDb? prev = null;

return Observable.Create((IObserver<Db> observer) =>
{
return dbStream.Subscribe(nextItem =>
{

if (prev != null && prev.Value >= nextItem.BasisTxId)
if (prev != null && prev.BasisTxId >= nextItem.BasisTxId)
return;

var db = (Db)nextItem;
Expand All @@ -65,7 +65,7 @@ private IObservable<Db> ProcessUpdate(IObservable<IDb> dbStream)
{
try
{
var result = analyzer.Analyze(nextItem);
var result = analyzer.Analyze(prev, nextItem);
db.AnalyzerData.Add(analyzer.GetType(), result);
}
catch (Exception ex)
Expand All @@ -75,7 +75,7 @@ private IObservable<Db> ProcessUpdate(IObservable<IDb> dbStream)
}

observer.OnNext((Db)nextItem);
prev = nextItem.BasisTxId;
prev = nextItem;
}, observer.OnError, observer.OnCompleted);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace NexusMods.MnemonicDB.TestModel.Analyzers;
/// </summary>
public class AttributesAnalyzer : IAnalyzer<HashSet<IAttribute>>
{
public object Analyze(IDb db)
public object Analyze(IDb? dbOld, IDb dbNew)
{
var hashSet = new HashSet<IAttribute>();
var registry = db.Registry;
foreach (var datom in db.RecentlyAdded)
var registry = dbNew.Registry;
foreach (var datom in dbNew.RecentlyAdded)
{
hashSet.Add(registry.GetAttribute(datom.A));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace NexusMods.MnemonicDB.TestModel.Analyzers;
/// </summary>
public class DatomCountAnalyzer : IAnalyzer<int>
{
public object Analyze(IDb db)
public object Analyze(IDb? dbOld, IDb dbNew)
{
return db.RecentlyAdded.Count;
return dbNew.RecentlyAdded.Count;
}
}

0 comments on commit 733fcfb

Please sign in to comment.