Skip to content

Commit 00a6eab

Browse files
committed
Merge branch 'develop'
2 parents ff11549 + f1e6ce3 commit 00a6eab

File tree

7 files changed

+78
-18
lines changed

7 files changed

+78
-18
lines changed

Damselfly.Core.DbModels/Models/Entities/ImageMetaData.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel.DataAnnotations;
3+
using System.Runtime.CompilerServices;
34

45
namespace Damselfly.Core.Models;
56

@@ -51,4 +52,24 @@ public class ImageMetaData
5152
// Date we last performed face/object/image recognition
5253
// If this is null, AI will be reprocessed
5354
public DateTime? AILastUpdated { get; set; }
55+
56+
public void Clear()
57+
{
58+
this.DateTaken = DateTime.MinValue;
59+
this.Height = 0;
60+
this.Width = 0;
61+
this.Description = null;
62+
this.Caption = null;
63+
this.DominantColor = null;
64+
this.AspectRatio = 1;
65+
this.Rating = 0;
66+
this.Credit = null;
67+
this.ISO = null;
68+
this.FNum = null;
69+
this.Exposure = null;
70+
this.FNum = null;
71+
this.FlashFired = false;
72+
this.Latitude = null;
73+
this.Longitude = null;
74+
}
5475
}

Damselfly.Core.ScopedServices/Client Services/ClientImageCacheService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ private async Task<Image> LoadAndCacheImage(int imageId)
171171
if (_memoryCache.TryGetValue<Image>(imageId, out var image))
172172
return image;
173173

174-
// This should never happen, if our caching is working. :)
175-
_logger.LogWarning($"No image found in client-side cache for ID: {imageId}.");
174+
_logger.LogTrace($"No image found in client-side cache for ID: {imageId}.");
176175

177176
try
178177
{

Damselfly.Core/Services/ImageRecognitionService.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,13 @@ public async Task CreateMissingPeople(IEnumerable<ImageDetectResult> detectedFac
328328
State = Person.PersonState.Unknown,
329329
LastUpdated = DateTime.UtcNow,
330330
PersonGuid = x.PersonGuid,
331-
FaceData = new List<PersonFaceData> { new()
332-
{
333-
Score = x.Score,
334-
Embeddings = string.Join( ",", x.Embeddings)
335-
} },
331+
FaceData = BuildFaceData(x),
336332
}).ToList();
337333

338334
if ( newPeople.Any() )
339335
{
340336
await db.People.AddRangeAsync( newPeople );
341-
await db.SaveChangesAsync();
337+
await db.SaveChangesAsync("AddPeople");
342338

343339
// Add or replace the new people in the cache (this should always add)
344340
newPeople.ForEach(x => _peopleCache[x.PersonGuid] = x);
@@ -352,6 +348,32 @@ public async Task CreateMissingPeople(IEnumerable<ImageDetectResult> detectedFac
352348
}
353349
}
354350

351+
/// <summary>
352+
/// Create the face data for an image detect result - being careful
353+
/// not to return anything if the detect result didn't actually
354+
/// contain any embeddings.
355+
/// </summary>
356+
/// <param name="detectResult"></param>
357+
/// <returns></returns>
358+
private List<PersonFaceData> BuildFaceData( ImageDetectResult detectResult )
359+
{
360+
List<PersonFaceData>? result = new();
361+
362+
if( detectResult.Embeddings.Length > 0 )
363+
{
364+
result = new List<PersonFaceData>
365+
{
366+
new()
367+
{
368+
Score = detectResult.Score,
369+
Embeddings = string.Join( ",", detectResult.Embeddings)
370+
}
371+
};
372+
}
373+
374+
return result;
375+
}
376+
355377
/// <summary>
356378
/// Given a collection of detected objects, create the tags, put them in the cache,
357379
/// and then return a list of keyword => TagID key-value pairs

Damselfly.Core/Services/MetaDataService.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void StartService()
185185

186186
_workService.AddJobSource(this);
187187
}
188-
188+
189189
/// <summary>
190190
/// Read the metadata, and handle any exceptions.
191191
/// </summary>
@@ -216,6 +216,20 @@ private IReadOnlyList<Directory> SafeReadImageMetadata(string imagePath)
216216
return metadata;
217217
}
218218

219+
private string? GetXMPFieldValue( Dictionary<string, string> kvps, string prefix )
220+
{
221+
if( kvps.TryGetValue( prefix, out var result ) && ! string.IsNullOrEmpty(result))
222+
return result;
223+
224+
var possibilities = Enumerable.Range(1, 5).Select( n => $"{prefix}[{n}]");
225+
226+
foreach( var key in possibilities )
227+
if( kvps.TryGetValue( key, out var indexed ) && ! string.IsNullOrEmpty(indexed) )
228+
return indexed;
229+
230+
return null;
231+
}
232+
219233
/// <summary>
220234
/// Pull out the XMP attributes
221235
/// </summary>
@@ -227,18 +241,19 @@ private void ReadXMPData(XmpDirectory xmpDirectory, Image image)
227241
{
228242
var nvps = xmpDirectory.XmpMeta.Properties
229243
.Where(x => !string.IsNullOrEmpty(x.Path))
230-
.ToDictionary(x => x.Path, y => y.Value);
244+
.ToDictionary(x => x.Path, y => y.Value, StringComparer.OrdinalIgnoreCase);
231245

232246
if( image.MetaData.DateTaken == DateTime.MinValue )
233247
{
234248
if( nvps.ContainsKey("exif:DateTimeOriginal") && DateTime.TryParse(nvps["exif:DateTimeOriginal"], out var dateTime) )
235249
image.MetaData.DateTaken = dateTime;
236250
}
237-
if( string.IsNullOrEmpty(image.MetaData.Description) && nvps.ContainsKey("exif:Description"))
238-
image.MetaData.Description = nvps["exif:Description"];
239-
240-
if( string.IsNullOrEmpty(image.MetaData.Caption) && nvps.ContainsKey("exif:Caption") )
241-
image.MetaData.Caption = nvps["exif:Caption"];
251+
252+
if( string.IsNullOrEmpty(image.MetaData.Description) )
253+
image.MetaData.Description = GetXMPFieldValue( nvps, "dc:Description" );
254+
255+
if( string.IsNullOrEmpty(image.MetaData.Caption) )
256+
image.MetaData.Caption = GetXMPFieldValue( nvps, "dc:Caption" );
242257
}
243258
catch ( Exception ex )
244259
{
@@ -359,6 +374,9 @@ private bool GetImageMetaData(ref ImageMetaData imgMetaData, out string[] keywor
359374

360375
if ( metadata != null )
361376
{
377+
// We've read some EXIF data, so clear out the existing metadata to replace it
378+
imgMetaData.Clear();
379+
362380
metaDataReadSuccess = true;
363381

364382
var subIfdDirectory = metadata.OfType<ExifSubIfdDirectory>().FirstOrDefault();

Damselfly.Core/Utils/DBSetExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ public static async Task<int> BulkUpdateWithSaveChanges<T>(this BaseDBModel db,
6161
dbSet.Update(e);
6262
}
6363

64-
return await db.SaveChangesAsync();
64+
return await db.SaveChangesAsync("BulkUpdateWithSaveChanges");
6565
}
6666
}

Damselfly.Web.Client/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static async Task Main(string[] args)
4545

4646
// Supply HttpClient instances that include access tokens when making requests to the server project
4747
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>().CreateClient("DamselflyAPI"));
48-
builder.Services.AddMemoryCache(x => x.SizeLimit = 5000);
48+
builder.Services.AddMemoryCache(x => x.SizeLimit = 500);
4949

5050
builder.Services.AddAuthorizationCore(config => config.SetupPolicies(builder.Services));
5151

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1.0
1+
4.1.1

0 commit comments

Comments
 (0)