Skip to content

Commit

Permalink
Fix tag writing
Browse files Browse the repository at this point in the history
  • Loading branch information
Webreaper committed Sep 20, 2022
1 parent f594efc commit e7fa359
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 49 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 5 additions & 3 deletions Damselfly.Core.DbModels/Models/Entities/Tag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ public enum TagTypes
Classification = 1
}

[Key] public int TagId { get; set; }
[Key]
public int TagId { get; set; }

[Required] public string Keyword { get; set; }
[Required]
public string Keyword { get; set; }

public TagTypes TagType { get; set; }
public bool Favourite { get; set; }

public DateTime TimeStamp { get; } = DateTime.UtcNow;
public DateTime TimeStamp { get; init; } = DateTime.UtcNow;

[JsonIgnore] // This JsonIgnore prevents circular references when serializing the Image entity
public virtual List<ImageTag> ImageTags { get; init; } = new();
Expand Down
62 changes: 31 additions & 31 deletions Damselfly.Core/Damselfly.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0-rc.1.22426.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-rc.1.22426.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.0-rc.1.22426.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0-rc.1.22426.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-rc.1.22426.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.0-rc.1.22426.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.0-rc.1.22426.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand All @@ -16,37 +16,37 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="MetadataExtractor" Version="2.7.2"/>
<PackageReference Include="CommandLineParser" Version="2.9.1"/>
<PackageReference Include="WordPressPCL" Version="2.0.0"/>
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3"/>
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14"/>
<PackageReference Include="font-awesome" Version="4.7.0"/>
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.63"/>
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.1-preview.63"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0-rc.1.22426.10"/>
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.0-rc.1.22427.2"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.0-rc.1.22427.2"/>
<PackageReference Include="SendGrid" Version="9.28.1"/>
<PackageReference Include="MailKit" Version="3.4.1"/>
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="7.0.0-rc.1.22427.2"/>
<PackageReference Include="CoenM.ImageSharp.ImageHash" Version="1.3.6"/>
<PackageReference Include="EFCore.BulkExtensions" Version="6.5.6"/>
<PackageReference Include="MetadataExtractor" Version="2.7.2" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="WordPressPCL" Version="2.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
<PackageReference Include="font-awesome" Version="4.7.0" />
<PackageReference Include="SkiaSharp" Version="2.88.1-preview.63" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.1-preview.63" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0-rc.1.22426.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="7.0.0-rc.1.22427.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.0-rc.1.22427.2" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="MailKit" Version="3.4.1" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="7.0.0-rc.1.22427.2" />
<PackageReference Include="CoenM.ImageSharp.ImageHash" Version="1.3.6" />
<PackageReference Include="EFCore.BulkExtensions" Version="6.5.6" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\"/>
<Folder Include="Utils\"/>
<Folder Include="ScopedServices\"/>
<Folder Include="DbAbstractions\"/>
<Folder Include="Services\" />
<Folder Include="Utils\" />
<Folder Include="ScopedServices\" />
<Folder Include="DbAbstractions\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Damselfly.Core.Interfaces\Damselfly.Core.Interfaces.csproj"/>
<ProjectReference Include="..\Damselfly.Core.DbModels\Damselfly.Core.DbModels.csproj"/>
<ProjectReference Include="..\Damselfly.ML.ObjectDetection.ML\Damselfly.ML.ObjectDetection.csproj"/>
<ProjectReference Include="..\Damselfly.ML.AzureFace\Damselfly.ML.AzureFace.csproj"/>
<ProjectReference Include="..\Damselfly.ML.EmguFace\Damselfly.ML.EmguFace.csproj"/>
<ProjectReference Include="..\Damselfly.ML.ImageClassification\Damselfly.ML.ImageClassification.csproj"/>
<ProjectReference Include="..\Damselfly.Core.ScopedServices\Damselfly.Core.ScopedServices.csproj"/>
<ProjectReference Include="..\Damselfly.Shared.Utils\Damselfly.Shared.Utils.csproj"/>
<ProjectReference Include="..\Damselfly.Core.Interfaces\Damselfly.Core.Interfaces.csproj" />
<ProjectReference Include="..\Damselfly.Core.DbModels\Damselfly.Core.DbModels.csproj" />
<ProjectReference Include="..\Damselfly.ML.ObjectDetection.ML\Damselfly.ML.ObjectDetection.csproj" />
<ProjectReference Include="..\Damselfly.ML.AzureFace\Damselfly.ML.AzureFace.csproj" />
<ProjectReference Include="..\Damselfly.ML.EmguFace\Damselfly.ML.EmguFace.csproj" />
<ProjectReference Include="..\Damselfly.ML.ImageClassification\Damselfly.ML.ImageClassification.csproj" />
<ProjectReference Include="..\Damselfly.Core.ScopedServices\Damselfly.Core.ScopedServices.csproj" />
<ProjectReference Include="..\Damselfly.Shared.Utils\Damselfly.Shared.Utils.csproj" />
</ItemGroup>
</Project>
7 changes: 1 addition & 6 deletions Damselfly.Core/Database/BaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public async Task<bool> BulkInsert<T>(DbSet<T> collection, List<T> itemsToSave)
try
{
var bulkConfig = new BulkConfig { SetOutputIdentity = true, BatchSize = 500 };

await this.BulkInsertAsync(itemsToSave, bulkConfig);

success = true;
Expand Down Expand Up @@ -113,11 +112,7 @@ public async Task<bool> BulkUpdate<T>(DbSet<T> collection, List<T> itemsToSave)
var success = false;
try
{
collection.UpdateRange(itemsToSave);
await SaveChangesAsync();

// TODO: Replace when EFCore 7 has this
//await db.BulkUpdateAsync(itemsToSave);
await this.BulkUpdateAsync(itemsToSave);

success = true;
}
Expand Down
9 changes: 7 additions & 2 deletions Damselfly.Core/ScopedServices/BasketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,23 @@ public async Task<Basket> GetDefaultBasket(int? userId)
// Get the first shared
defaultBasket = await db.Baskets
.Include(x => x.BasketEntries)
.OrderBy( x => x.Name )
.FirstOrDefaultAsync(x => x.UserId == null);

if ( defaultBasket == null )
if (defaultBasket == null)
{
// Get the first default basket
defaultBasket = await db.Baskets
.Include(x => x.BasketEntries)
.FirstOrDefaultAsync(x => x.Name == s_DefaultBasket);
}

if ( defaultBasket == null )
{
// Probably shouldn't ever happen, but just pick the first one
defaultBasket = db.Baskets.First();
defaultBasket = await db.Baskets
.OrderBy( x => x.Name )
.FirstAsync();

// TODO: If still null, should we create one?
throw new ArgumentException("No baskets - this is unexpected!");
Expand Down
2 changes: 1 addition & 1 deletion Damselfly.Core/Services/MetaDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ private async Task<int> WriteTagsForImage(Image image, List<string> imageKeyword
{
var addWatch = new Stopwatch("AddTagsInsert");
await db.BulkInsert(db.ImageTags, toAdd);
;

addWatch.Stop();
}

Expand Down
12 changes: 6 additions & 6 deletions Damselfly.Migrations.Sqlite/Damselfly.Migrations.Sqlite.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<Folder Include="Migrations\"/>
<Folder Include="Migrations\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Damselfly.Core\Damselfly.Core.csproj"/>
<ProjectReference Include="..\Damselfly.Core.DbModels\Damselfly.Core.DbModels.csproj"/>
<ProjectReference Include="..\Damselfly.Core\Damselfly.Core.csproj" />
<ProjectReference Include="..\Damselfly.Core.DbModels\Damselfly.Core.DbModels.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0-rc.1.22426.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="EFCore.BulkExtensions" Version="6.5.6"/>
<PackageReference Include="EFCore.BulkExtensions" Version="6.5.6" />
</ItemGroup>
<ItemGroup>
<None Remove="Microsoft.EntityFrameworkCore.Tools"/>
<None Remove="Z.EntityFramework.Extensions.EFCore"/>
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
<None Remove="Z.EntityFramework.Extensions.EFCore" />
</ItemGroup>
</Project>

0 comments on commit e7fa359

Please sign in to comment.