mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 15:26:30 +00:00
huge queue refactoring:
3 queues -> 1 queue send delete validate updates
This commit is contained in:
@@ -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