mirror of
https://github.com/azaion/annotations.git
synced 2026-04-23 02:46:30 +00:00
huge queue refactoring:
3 queues -> 1 queue send delete validate updates
This commit is contained in:
@@ -59,5 +59,7 @@ public enum AnnotationStatus
|
||||
{
|
||||
None = 0,
|
||||
Created = 10,
|
||||
Validated = 20
|
||||
Validated = 20,
|
||||
ValidatedEdited = 25,
|
||||
Deleted = 30
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Azaion.Common.Database;
|
||||
|
||||
public class AnnotationName
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Azaion.Common.Database;
|
||||
|
||||
public class AnnotationQueueRecord
|
||||
{
|
||||
public DateTime DateTime { get; set; }
|
||||
public AnnotationStatus Operation { get; set; }
|
||||
public List<string> AnnotationNames { get; set; } = null!;
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Azaion.Common.Database;
|
||||
public class AnnotationsDb(DataOptions dataOptions) : DataConnection(dataOptions)
|
||||
{
|
||||
public ITable<Annotation> Annotations => this.GetTable<Annotation>();
|
||||
public ITable<AnnotationName> AnnotationsQueue => this.GetTable<AnnotationName>();
|
||||
public ITable<AnnotationQueueRecord> AnnotationsQueueRecords => this.GetTable<AnnotationQueueRecord>();
|
||||
public ITable<Detection> Detections => this.GetTable<Detection>();
|
||||
public ITable<QueueOffset> QueueOffsets => this.GetTable<QueueOffset>();
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using LinqToDB.DataProvider.SQLite;
|
||||
using LinqToDB.Mapping;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Azaion.Common.Database;
|
||||
|
||||
@@ -17,7 +18,6 @@ public interface IDbFactory
|
||||
Task<T> Run<T>(Func<AnnotationsDb, Task<T>> func);
|
||||
Task Run(Func<AnnotationsDb, Task> func);
|
||||
void SaveToDisk();
|
||||
Task DeleteAnnotations(List<Annotation> annotations, CancellationToken cancellationToken = default);
|
||||
Task DeleteAnnotations(List<string> annotationNames, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class DbFactory : IDbFactory
|
||||
SQLiteConnection.CreateFile(_annConfig.AnnotationsDbFile);
|
||||
using var db = new AnnotationsDb(_fileDataOptions);
|
||||
db.CreateTable<Annotation>();
|
||||
db.CreateTable<AnnotationName>();
|
||||
db.CreateTable<AnnotationQueueRecord>();
|
||||
db.CreateTable<Detection>();
|
||||
db.CreateTable<QueueOffset>();
|
||||
db.QueueOffsets.BulkCopy(new List<QueueOffset>
|
||||
@@ -98,12 +98,6 @@ public class DbFactory : IDbFactory
|
||||
_memoryConnection.BackupDatabase(_fileConnection, "main", "main", -1, null, -1);
|
||||
}
|
||||
|
||||
public async Task DeleteAnnotations(List<Annotation> annotations, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var names = annotations.Select(x => x.Name).ToList();
|
||||
await DeleteAnnotations(names, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task DeleteAnnotations(List<string> annotationNames, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await Run(async db =>
|
||||
@@ -142,8 +136,11 @@ public static class AnnotationsDbSchemaHolder
|
||||
builder.Entity<Detection>()
|
||||
.HasTableName(Constants.DETECTIONS_TABLENAME);
|
||||
|
||||
builder.Entity<AnnotationName>()
|
||||
.HasTableName(Constants.ANNOTATIONS_QUEUE_TABLENAME);
|
||||
builder.Entity<AnnotationQueueRecord>()
|
||||
.HasTableName(Constants.ANNOTATIONS_QUEUE_TABLENAME)
|
||||
.Property(x => x.AnnotationNames)
|
||||
.HasDataType(DataType.NVarChar)
|
||||
.HasConversion(list => JsonConvert.SerializeObject(list), str => JsonConvert.DeserializeObject<List<string>>(str) ?? new List<string>());
|
||||
|
||||
builder.Build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user