Skip to content

Commit

Permalink
More code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Feb 21, 2024
1 parent fb3108f commit d0b3b1d
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection;
using NexusMods.EventSourcing.Abstractions;
using NexusMods.EventSourcing.TestModel.Model;
// ReSharper disable MemberCanBePrivate.Global

namespace NexusMods.EventSourcing.Benchmarks.Benchmarks;

Expand All @@ -23,7 +24,7 @@ public ReadTests()
_connection = services.GetRequiredService<IConnection>();
}

public const int MaxCount = 10000;
private const int MaxCount = 10000;

[GlobalSetup]
public void Setup()
Expand Down Expand Up @@ -53,7 +54,7 @@ public void Setup()


[Params(1, 1000, MaxCount)]
public int Count { get; set; } = MaxCount;
public int Count { get; init; } = MaxCount;

public enum SortOrder
{
Expand Down
4 changes: 4 additions & 0 deletions qodana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ profile:
exclude:
- name: ClassNeverInstantiated.Global
- name: UnusedAutoPropertyAccessor.Global
- name: InconsistentNaming
paths:
- src\NexusMods.EventSourcing.DatomStore\Indexes
- name: UnusedMemberInSuper.Global
2 changes: 1 addition & 1 deletion src/NexusMods.EventSourcing.Abstractions/ITransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface ITransaction
/// as asserts for each property with the FromAttribute
/// </summary>
/// <param name="model"></param>
TReadModel Add<TReadModel>(TReadModel model)
void Add<TReadModel>(TReadModel model)
where TReadModel : IReadModel;

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/NexusMods.EventSourcing.Abstractions/Ids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum Partition
/// <param name="partition"></param>
/// <param name="id"></param>
/// <returns></returns>
public static ulong MakeId(Partition partition, ulong id)
private static ulong MakeId(Partition partition, ulong id)
{
return ((ulong)partition << 56) | (id & 0x00FFFFFFFFFFFFFF);
}
Expand Down Expand Up @@ -63,7 +63,7 @@ public static ulong MinId(Partition partition)
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static Partition GetPartition(ulong id)
private static Partition GetPartition(ulong id)
{
return (id >> 56) switch
{
Expand Down
5 changes: 0 additions & 5 deletions src/NexusMods.EventSourcing.Abstractions/Models/AReadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace NexusMods.EventSourcing.Abstractions.Models;
/// <summary>
/// Base class for all read models.
/// </summary>
/// <param name="id"></param>
public abstract class AReadModel<TOuter> : IReadModel
where TOuter : AReadModel<TOuter>, IReadModel
{
Expand All @@ -24,10 +23,6 @@ protected AReadModel(ITransaction? tx)
/// <summary>
/// Retrieves the read model from the database
/// </summary>
/// <param name="tx"></param>
/// <typeparam name="TReadModel"></typeparam>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
protected TReadModel Get<TReadModel>(EntityId entityId)
where TReadModel : AReadModel<TReadModel>, IReadModel
{
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions src/NexusMods.EventSourcing.Abstractions/ScalarAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class ScalarAttribute<TAttribute, TValueType> : IAttribute<TValueType>
/// <summary>
/// Create a new attribute
/// </summary>
/// <param name="guid"></param>
protected ScalarAttribute(string uniqueName = "")
{
if (uniqueName == "")
Expand All @@ -26,7 +25,6 @@ protected ScalarAttribute(string uniqueName = "")
/// <summary>
/// Create a new attribute from an already parsed guid
/// </summary>
/// <param name="guid"></param>
protected ScalarAttribute(Symbol symbol)
{
Id = symbol;
Expand Down
8 changes: 4 additions & 4 deletions src/NexusMods.EventSourcing.DatomStore/BuiltInAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public class UniqueId() : ScalarAttribute<UniqueId, Symbol>(UniqueIdStaticId);
/// <summary>
/// Static unique id of the UniqueId attribute
/// </summary>
public static readonly Symbol UniqueIdStaticId = Symbol.Intern("NexusMods.EventSourcing.DatomStore/UniqueId");
private static readonly Symbol UniqueIdStaticId = Symbol.Intern("NexusMods.EventSourcing.DatomStore/UniqueId");

/// <summary>
/// The database entity id of the UniqueId attribute
/// </summary>
public static readonly ulong UniqueIdEntityId = 1;
private static readonly ulong UniqueIdEntityId = 1;

/// <summary>
/// The unique id if the IValueSerializer used to serialize the value of the attribute.
Expand All @@ -29,12 +29,12 @@ public class ValueSerializerId() : ScalarAttribute<ValueSerializerId, UInt128>("
/// <summary>
/// Static unique id of the UniqueId attribute
/// </summary>
public static readonly Symbol ValueSerializerIdStaticId = Symbol.Intern("NexusMods.EventSourcing.DatomStore/ValueSerializerId");
private static readonly Symbol ValueSerializerIdStaticId = Symbol.Intern("NexusMods.EventSourcing.DatomStore/ValueSerializerId");

/// <summary>
/// The database entity id of the UniqueId attribute
/// </summary>
public static readonly ulong ValueSerializerIdEntityId = 2;
private static readonly ulong ValueSerializerIdEntityId = 2;


/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BoolSerializer : IValueSerializer<bool>
/// <inheritdoc />
public Type NativeType => typeof(bool);

public static readonly UInt128 Id = "50BECA70-43D9-497D-B47C-8AD8B85B7801".ToUInt128Guid();
private static readonly UInt128 Id = "50BECA70-43D9-497D-B47C-8AD8B85B7801".ToUInt128Guid();

/// <inheritdoc />
public UInt128 UniqueId => Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class EntityIdSerialzer : IValueSerializer<EntityId>
{
public Type NativeType => typeof(EntityId);

public static readonly UInt128 Id = "E2C3185E-C082-4641-B25E-7CEC803A2F48".ToUInt128Guid();
private static readonly UInt128 Id = "E2C3185E-C082-4641-B25E-7CEC803A2F48".ToUInt128Guid();
public UInt128 UniqueId => Id;
public int Compare(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class SymbolSerializer : IValueSerializer<Symbol>
{
public Type NativeType => typeof(Symbol);

public static readonly UInt128 Id = "1BAE8D48-8775-4642-AEA9-9C925B30D4B2".ToUInt128Guid();
private static readonly UInt128 Id = "1BAE8D48-8775-4642-AEA9-9C925B30D4B2".ToUInt128Guid();
public UInt128 UniqueId => Id;
public int Compare(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class TxIdSerializer : IValueSerializer<TxId>
{
public Type NativeType => typeof(TxId);

public static readonly UInt128 Id = "BB2B2BAF-9AA8-4DB0-8BFC-A0A853ED9BA0".ToUInt128Guid();
private static readonly UInt128 Id = "BB2B2BAF-9AA8-4DB0-8BFC-A0A853ED9BA0".ToUInt128Guid();
public UInt128 UniqueId => Id;
public int Compare(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ public class DatomStoreSettings
/// <summary>
/// The path to the directory where the RocksDB database will be stored.
/// </summary>
public AbsolutePath Path { get; set; }
public AbsolutePath Path { get; init; }
}
5 changes: 2 additions & 3 deletions src/NexusMods.EventSourcing.DatomStore/RocksDBDatomStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Logging;
using NexusMods.EventSourcing.Abstractions;
using NexusMods.EventSourcing.DatomStore.Indexes;
using RocksDbSharp;
Expand All @@ -22,7 +21,7 @@ public class RocksDBDatomStore : IDatomStore
private readonly EATVIndex _eatvIndex;
private readonly AVTEIndex _avteIndex;

public RocksDBDatomStore(ILogger<RocksDBDatomStore> logger, AttributeRegistry registry, DatomStoreSettings settings)
public RocksDBDatomStore(AttributeRegistry registry, DatomStoreSettings settings)
{
_registry = registry;
_registry.Populate(BuiltInAttributes.Initial);
Expand Down Expand Up @@ -68,7 +67,7 @@ private void Serialize<TAttr, TVal>(WriteBatch batch, ulong e, TVal val, ulong t
_avteIndex.Put(batch, span);
}

private struct TransactSink(RocksDBDatomStore store, WriteBatch batch, ulong tx) : IDatomSink
private readonly struct TransactSink(RocksDBDatomStore store, WriteBatch batch, ulong tx) : IDatomSink
{
public void Datom<TAttr, TVal>(ulong e, TVal v, bool isAssert) where TAttr : IAttribute<TVal>
{
Expand Down
11 changes: 0 additions & 11 deletions src/NexusMods.EventSourcing/Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ internal class Db(IDatomStore store, Connection connection, TxId txId) : IDb
{
public TxId BasisTxId => txId;


public IIterator Where<TAttr>() where TAttr : IAttribute
{
return store.Where<TAttr>(txId);
}

public IIterator Where(EntityId id)
{
throw new NotImplementedException();
}

public IEnumerable<TModel> Get<TModel>(IEnumerable<EntityId> ids) where TModel : IReadModel
{
using var iterator = store.EntityIterator(txId);
Expand Down
2 changes: 1 addition & 1 deletion src/NexusMods.EventSourcing/ModelReflector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public ReaderFn<TModel> GetReader<TModel>() where TModel : IReadModel
return readerFn;
}

public ReaderFn<TModel> MakeReader<TModel>() where TModel : IReadModel
private ReaderFn<TModel> MakeReader<TModel>() where TModel : IReadModel
{
var properties = GetModelProperties(typeof(TModel));

Expand Down
2 changes: 1 addition & 1 deletion src/NexusMods.EventSourcing/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Add(IDatom datom)
}

/// <inheritdoc />
public TReadModel Add<TReadModel>(TReadModel model)
public void Add<TReadModel>(TReadModel model)
where TReadModel : IReadModel
{
_models.Add(model);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using NexusMods.EventSourcing.Abstractions;
using NexusMods.EventSourcing.Abstractions;
using NexusMods.Paths;
// ReSharper disable PossibleMultipleEnumeration
// ReSharper disable MemberCanBePrivate.Global

namespace NexusMods.EventSourcing.DatomStore.Tests;

Expand All @@ -19,7 +19,7 @@ protected ADatomStoreTest(IEnumerable<IValueSerializer> valueSerializers, IEnume
Path = _tmpPath,
};
var registry = new AttributeRegistry(valueSerializers, attributes);
Store = new RocksDBDatomStore(new NullLogger<RocksDBDatomStore>(), registry, dbSettings);
Store = new RocksDBDatomStore(registry, dbSettings);
Connection = new Connection(Store, attributes, valueSerializers);
}

Expand Down
5 changes: 2 additions & 3 deletions tests/NexusMods.EventSourcing.Tests/AEventSourcingTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging.Abstractions;
using NexusMods.EventSourcing.Abstractions;
using NexusMods.EventSourcing.Abstractions;
using NexusMods.EventSourcing.DatomStore;
using NexusMods.Paths;

Expand All @@ -23,7 +22,7 @@ protected AEventSourcingTest(IEnumerable<IValueSerializer> valueSerializers,

var attributeArray = attributes.ToArray();
var registry = new AttributeRegistry(valueSerializerArray, attributeArray);
Store = new RocksDBDatomStore(new NullLogger<RocksDBDatomStore>(), registry, dbSettings);
Store = new RocksDBDatomStore(registry, dbSettings);
Connection = new Connection(Store, attributeArray, valueSerializerArray);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/NexusMods.EventSourcing.Tests/DbTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ReadDatomsForEntity()
[Fact]
public void DbIsImmutable()
{
const int TIMES = 10;
const int times = 10;

// Insert some data
var tx = Connection.BeginTransaction();
Expand All @@ -72,7 +72,7 @@ public void DbIsImmutable()
found.Index.Should().Be(0);

// Mutate the data
for (var i = 0; i < TIMES; i++)
for (var i = 0; i < times; i++)
{
var newTx = Connection.BeginTransaction();
ModFileAttributes.Path.Add(newTx, realId, $"C:\\test_{i}.txt_mutate");
Expand Down

0 comments on commit d0b3b1d

Please sign in to comment.