fix ui bugs, fix RefreshThumbnails method

This commit is contained in:
Alex Bezdieniezhnykh
2025-04-14 19:43:14 +03:00
parent dd42292eee
commit 1287c13516
5 changed files with 62 additions and 27 deletions
+2 -1
View File
@@ -147,7 +147,7 @@ public class AnnotationService : INotificationHandler<AnnotationsDeletedEvent>
: AnnotationStatus.Created;
await db.Detections.DeleteAsync(x => x.AnnotationName == fName, token: token);
await db.BulkCopyAsync(detections, cancellationToken: token);
if (ann != null)
{
await db.Annotations
@@ -177,6 +177,7 @@ public class AnnotationService : INotificationHandler<AnnotationsDeletedEvent>
};
await db.InsertAsync(ann, token: token);
}
await db.BulkCopyAsync(detections, cancellationToken: token);
return ann;
});
+23 -6
View File
@@ -73,7 +73,7 @@ public class GalleryService(
await _updateLock.WaitAsync();
var existingAnnotations = new ConcurrentDictionary<string, Annotation>(await dbFactory.Run(async db =>
await db.Annotations.ToDictionaryAsync(x => x.Name)));
var missedAnnotations = new ConcurrentBag<Annotation>();
var missedAnnotations = new ConcurrentDictionary<string, Annotation>();
try
{
var prefixLen = Constants.THUMBNAIL_PREFIX.Length;
@@ -89,7 +89,7 @@ public class GalleryService(
await ParallelExt.ForEachAsync(files, async (file, cancellationToken) =>
{
var fName = Path.GetFileNameWithoutExtension(file.Name);
var fName = file.Name.ToFName();
try
{
var labelName = Path.Combine(_dirConfig.LabelsDirectory, $"{fName}.txt");
@@ -136,7 +136,7 @@ public class GalleryService(
{
Time = time,
OriginalMediaName = originalMediaName,
Name = file.Name.ToFName(),
Name = fName,
ImageExtension = Path.GetExtension(file.Name),
Detections = detections,
CreatedDate = File.GetCreationTimeUtc(file.FullName),
@@ -146,8 +146,15 @@ public class GalleryService(
AnnotationStatus = AnnotationStatus.Validated
};
//Remove duplicates
if (!existingAnnotations.ContainsKey(fName))
missedAnnotations.Add(annotation);
{
if (missedAnnotations.ContainsKey(fName))
Console.WriteLine($"{fName} is already exists! Duplicate!");
else
missedAnnotations.TryAdd(fName, annotation);
}
if (!thumbnails.Contains(fName))
await CreateThumbnail(annotation, cancellationToken);
@@ -181,10 +188,20 @@ public class GalleryService(
{
MaxBatchSize = 50
};
//Db could be updated during the long files scraping
existingAnnotations = new ConcurrentDictionary<string, Annotation>(await dbFactory.Run(async db =>
await db.Annotations.ToDictionaryAsync(x => x.Name)));
var insertedDuplicates = missedAnnotations.Where(x => existingAnnotations.ContainsKey(x.Key)).ToList();
var annotationsToInsert = missedAnnotations
.Where(a => !existingAnnotations.ContainsKey(a.Key))
.Select(x => x.Value)
.ToList();
await dbFactory.Run(async db =>
{
await db.BulkCopyAsync(copyOptions, missedAnnotations);
await db.BulkCopyAsync(copyOptions, missedAnnotations.SelectMany(x => x.Detections));
await db.BulkCopyAsync(copyOptions, annotationsToInsert);
await db.BulkCopyAsync(copyOptions, annotationsToInsert.SelectMany(x => x.Detections));
});
dbFactory.SaveToDisk();
_updateLock.Release();