Skip to content

Commit

Permalink
First working duplicated page #78
Browse files Browse the repository at this point in the history
  • Loading branch information
Webreaper committed Jan 18, 2021
1 parent 9507548 commit 71c53f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
25 changes: 16 additions & 9 deletions Damselfly.Web/Data/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,27 @@ public static List<List<Image>> GetImagesWithDuplicates()
var watch = new Stopwatch("GetImagesWithDupes");

// Craft the SQL manually as server-side groupby isn't supported by EF Core.
var sql = "SELECT im.* from ImageMetaData im where im.hash in (SELECT hash from ImageMetaData where hash is not null group by hash having count( distinct ImageID ) > 1)";
// Select all images that have the same hash as more than one image.
var subQuery = "SELECT hash from ImageMetaData where hash is not null and hash <> \"\" group by hash having count( distinct ImageID ) > 1";
var sql = $"SELECT im.* from ImageMetaData im where im.hash in ({subQuery})";

var dupeImageMetaData = db.ImageMetaData.FromSqlRaw(sql)
.Include(x => x.Image)
.ThenInclude(x => x.Folder)
.Select( x => x.Image )
.ToList();
var dupes = db.ImageMetaData.FromSqlRaw(sql)
.Where(x => x.Hash != null)
.Include(x => x.Image)
.ThenInclude(x => x.Folder)
.ToList();

// Backfill the metadata for the child image object, so we can select it.
dupes.ForEach(x => x.Image.MetaData = x );

var listOfLists = dupeImageMetaData.Where( x => x.MetaData != null )
// Group by the hash and pick all of the images for each one.
var listOfLists = dupes.Select( x => x.Image )
.GroupBy(x => x.MetaData.Hash)
.Where( x => x != null )
.Select( x => x.ToList() )
.Select( x => x.OrderBy( x => x.SortDate ).ToList() )
.ToList();

watch.Stop();

return listOfLists;
}

Expand Down
8 changes: 7 additions & 1 deletion Damselfly.Web/Pages/DuplicatesPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
@foreach (var img in list)
{
<div>
@img.FileName
@img.FullPath
<img src="@GetImgUrl( img )" />;
</div>
}

Expand All @@ -42,6 +43,11 @@

List<List<Image>> imageLists = new List<List<Image>>();

private string GetImgUrl( Image image )
{
return $"/thumb/{ThumbSize.Small}/{image.ImageId}";
}

public Task<List<List<Image>>> LoadData()
{
var watch = new Stopwatch("DupesLoadData");
Expand Down

0 comments on commit 71c53f4

Please sign in to comment.