mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:06:30 +00:00
fix ui bugs, fix RefreshThumbnails method
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user