mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* use etags to optimize local movie scanner * use etags to optimize local television scanner * use etags to optimize local music video scanner * code cleanuppull/197/head v0.0.37-prealpha
20 changed files with 2774 additions and 68 deletions
@ -0,0 +1,11 @@ |
|||||||
|
namespace ErsatzTV.Core.Domain |
||||||
|
{ |
||||||
|
public class LibraryFolder |
||||||
|
{ |
||||||
|
public int Id { get; set; } |
||||||
|
public string Path { get; set; } |
||||||
|
public int LibraryPathId { get; set; } |
||||||
|
public LibraryPath LibraryPath { get; set; } |
||||||
|
public string Etag { get; set; } |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,35 @@ |
|||||||
|
using System.Collections.Generic; |
||||||
|
using System.Linq; |
||||||
|
using System.Security.Cryptography; |
||||||
|
using System.Text; |
||||||
|
using ErsatzTV.Core.Interfaces.Metadata; |
||||||
|
using static LanguageExt.Prelude; |
||||||
|
|
||||||
|
namespace ErsatzTV.Core.Metadata |
||||||
|
{ |
||||||
|
public static class FolderEtag |
||||||
|
{ |
||||||
|
private static readonly MD5CryptoServiceProvider Crypto = new(); |
||||||
|
|
||||||
|
public static string Calculate(string folder, ILocalFileSystem localFileSystem) |
||||||
|
{ |
||||||
|
IEnumerable<string> allFiles = localFileSystem.ListFiles(folder); |
||||||
|
|
||||||
|
var sb = new StringBuilder(); |
||||||
|
foreach (string file in allFiles.OrderBy(identity)) |
||||||
|
{ |
||||||
|
sb.Append(file); |
||||||
|
sb.Append(localFileSystem.GetLastWriteTime(file).Ticks); |
||||||
|
} |
||||||
|
|
||||||
|
var hash = new StringBuilder(); |
||||||
|
byte[] bytes = Crypto.ComputeHash(Encoding.UTF8.GetBytes(sb.ToString())); |
||||||
|
foreach (byte t in bytes) |
||||||
|
{ |
||||||
|
hash.Append(t.ToString("x2")); |
||||||
|
} |
||||||
|
|
||||||
|
return hash.ToString(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,11 @@ |
|||||||
|
using ErsatzTV.Core.Domain; |
||||||
|
using Microsoft.EntityFrameworkCore; |
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.Data.Configurations |
||||||
|
{ |
||||||
|
public class LibraryFolderConfiguration : IEntityTypeConfiguration<LibraryFolder> |
||||||
|
{ |
||||||
|
public void Configure(EntityTypeBuilder<LibraryFolder> builder) => builder.ToTable("LibraryFolder"); |
||||||
|
} |
||||||
|
} |
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,40 @@ |
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||||
|
|
||||||
|
namespace ErsatzTV.Infrastructure.Migrations |
||||||
|
{ |
||||||
|
public partial class Add_LibraryFolder : Migration |
||||||
|
{ |
||||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||||
|
{ |
||||||
|
migrationBuilder.CreateTable( |
||||||
|
"LibraryFolder", |
||||||
|
table => new |
||||||
|
{ |
||||||
|
Id = table.Column<int>("INTEGER", nullable: false) |
||||||
|
.Annotation("Sqlite:Autoincrement", true), |
||||||
|
Path = table.Column<string>("TEXT", nullable: true), |
||||||
|
LibraryPathId = table.Column<int>("INTEGER", nullable: false), |
||||||
|
Etag = table.Column<string>("TEXT", nullable: true) |
||||||
|
}, |
||||||
|
constraints: table => |
||||||
|
{ |
||||||
|
table.PrimaryKey("PK_LibraryFolder", x => x.Id); |
||||||
|
table.ForeignKey( |
||||||
|
"FK_LibraryFolder_LibraryPath_LibraryPathId", |
||||||
|
x => x.LibraryPathId, |
||||||
|
"LibraryPath", |
||||||
|
"Id", |
||||||
|
onDelete: ReferentialAction.Cascade); |
||||||
|
}); |
||||||
|
|
||||||
|
migrationBuilder.CreateIndex( |
||||||
|
"IX_LibraryFolder_LibraryPathId", |
||||||
|
"LibraryFolder", |
||||||
|
"LibraryPathId"); |
||||||
|
} |
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder) => |
||||||
|
migrationBuilder.DropTable( |
||||||
|
"LibraryFolder"); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue