Skip to content

Commit

Permalink
fix: re-use file-name-hash entries
Browse files Browse the repository at this point in the history
- Re-use the file-name-hash entry for the same name and file-size even if the hash differs, because of the unique constraint placed upon the database table which disallows multiple entries with the same name and file size to exist in the table.
  • Loading branch information
revam committed Sep 16, 2024
1 parent 270ba2c commit e28feb8
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions Shoko.Server/Services/VideoLocal_PlaceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,18 +360,15 @@ public async Task<RelocationResult> DirectlyRelocateFile(SVR_VideoLocal_Place pl

if (renamed)
{
// Add a new lookup entry.
var filenameHash = RepoFactory.FileNameHash.GetByHash(place.VideoLocal.Hash);
if (!filenameHash.Any(a => a.FileName.Equals(newFileName)))
// Add a new or update an existing lookup entry.
var video = place.VideoLocal;
var existingEntries = RepoFactory.FileNameHash.GetByHash(video.Hash);
if (!existingEntries.Any(a => a.FileName.Equals(newFileName)))
{
var file = place.VideoLocal;
var hash = new FileNameHash
{
DateTimeUpdated = DateTime.Now,
FileName = newFileName,
FileSize = file.FileSize,
Hash = file.Hash,
};
var hash = RepoFactory.FileNameHash.GetByFileNameAndSize(newFileName, video.FileSize).FirstOrDefault() ??
new() { FileName = newFileName, FileSize = video.FileSize };
hash.DateTimeUpdated = DateTime.Now;
hash.Hash = video.Hash;
RepoFactory.FileNameHash.Save(hash);
}
}
Expand Down

0 comments on commit e28feb8

Please sign in to comment.