mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Fixing duplicated seasons
This commit is contained in:
parent
ef84a969b7
commit
7be4133af9
@ -30,9 +30,9 @@ namespace Kyoo.Controllers
|
||||
return _database.DisposeAsync();
|
||||
}
|
||||
|
||||
public async Task<Season> Get(int id)
|
||||
public Task<Season> Get(int id)
|
||||
{
|
||||
return await _database.Seasons.FirstOrDefaultAsync(x => x.ID == id);
|
||||
return _database.Seasons.FirstOrDefaultAsync(x => x.ID == id);
|
||||
}
|
||||
|
||||
public Task<Season> Get(string slug)
|
||||
@ -46,9 +46,9 @@ namespace Kyoo.Controllers
|
||||
return Get(showSlug, seasonNumber);
|
||||
}
|
||||
|
||||
public async Task<Season> Get(string showSlug, int seasonNumber)
|
||||
public Task<Season> Get(string showSlug, int seasonNumber)
|
||||
{
|
||||
return await _database.Seasons.FirstOrDefaultAsync(x => x.Show.Slug == showSlug
|
||||
return _database.Seasons.FirstOrDefaultAsync(x => x.Show.Slug == showSlug
|
||||
&& x.SeasonNumber == seasonNumber);
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,8 @@ namespace Kyoo.Controllers
|
||||
public async Task<ICollection<Show>> Search(string query)
|
||||
{
|
||||
return await _database.Shows
|
||||
.FromSqlInterpolated($@"SELECT * FROM Shows WHERE Shows.Title LIKE {$"%{query}%"}
|
||||
OR Shows.Aliases LIKE {$"%{query}%"}")
|
||||
.FromSqlInterpolated($@"SELECT * FROM Shows WHERE 'Shows.Title' LIKE {$"%{query}%"}
|
||||
OR 'Shows.Aliases' LIKE {$"%{query}%"}")
|
||||
.Take(20)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
@ -136,15 +136,18 @@ namespace Kyoo
|
||||
modelBuilder.Entity<People>()
|
||||
.HasIndex(x => x.Slug)
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<Show>()
|
||||
.HasIndex(x => x.Slug)
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<Studio>()
|
||||
.HasIndex(x => x.Slug)
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<ProviderID>()
|
||||
.HasIndex(x => x.Name)
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<Season>()
|
||||
.HasIndex(x => new {x.ShowID, x.SeasonNumber})
|
||||
.IsUnique();
|
||||
modelBuilder.Entity<Episode>()
|
||||
.HasIndex(x => new {x.ShowID, x.SeasonNumber, x.EpisodeNumber, x.AbsoluteNumber})
|
||||
.IsUnique();
|
||||
}
|
||||
|
||||
public void DiscardChanges()
|
||||
|
@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
{
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20200607010830_Initial")]
|
||||
[Migration("20200618133537_Initial")]
|
||||
partial class Initial
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -117,7 +117,8 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
|
||||
b.HasIndex("SeasonID");
|
||||
|
||||
b.HasIndex("ShowID");
|
||||
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Episodes");
|
||||
});
|
||||
@ -374,7 +375,8 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("ShowID");
|
||||
b.HasIndex("ShowID", "SeasonNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Seasons");
|
||||
});
|
||||
@ -430,9 +432,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("Slug")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("StudioID");
|
||||
|
||||
b.ToTable("Shows");
|
@ -423,9 +423,10 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
column: "SeasonID");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Episodes_ShowID",
|
||||
name: "IX_Episodes_ShowID_SeasonNumber_EpisodeNumber_AbsoluteNumber",
|
||||
table: "Episodes",
|
||||
column: "ShowID");
|
||||
columns: new[] { "ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_GenreLinks_GenreID",
|
||||
@ -517,14 +518,9 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Seasons_ShowID",
|
||||
name: "IX_Seasons_ShowID_SeasonNumber",
|
||||
table: "Seasons",
|
||||
column: "ShowID");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Shows_Slug",
|
||||
table: "Shows",
|
||||
column: "Slug",
|
||||
columns: new[] { "ShowID", "SeasonNumber" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
@ -115,7 +115,8 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
|
||||
b.HasIndex("SeasonID");
|
||||
|
||||
b.HasIndex("ShowID");
|
||||
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Episodes");
|
||||
});
|
||||
@ -372,7 +373,8 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("ShowID");
|
||||
b.HasIndex("ShowID", "SeasonNumber")
|
||||
.IsUnique();
|
||||
|
||||
b.ToTable("Seasons");
|
||||
});
|
||||
@ -428,9 +430,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.HasIndex("Slug")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("StudioID");
|
||||
|
||||
b.ToTable("Shows");
|
||||
|
@ -28,6 +28,8 @@ namespace Kyoo.Controllers
|
||||
private ITranscoder _transcoder;
|
||||
private IConfiguration _config;
|
||||
|
||||
private int _parallelTasks;
|
||||
|
||||
public async Task<IEnumerable<string>> GetPossibleParameters()
|
||||
{
|
||||
using IServiceScope serviceScope = _serviceProvider.CreateScope();
|
||||
@ -50,6 +52,9 @@ namespace Kyoo.Controllers
|
||||
_metadataProvider = serviceProvider.GetService<IProviderManager>();
|
||||
_transcoder = serviceProvider.GetService<ITranscoder>();
|
||||
_config = serviceProvider.GetService<IConfiguration>();
|
||||
_parallelTasks = _config.GetValue<int>("parallelTasks");
|
||||
if (_parallelTasks <= 0)
|
||||
_parallelTasks = 30;
|
||||
|
||||
using IServiceScope serviceScope = _serviceProvider.CreateScope();
|
||||
await using ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
|
||||
@ -112,18 +117,16 @@ namespace Kyoo.Controllers
|
||||
.GroupBy(Path.GetDirectoryName)
|
||||
.ToList();
|
||||
|
||||
// Todo batch wth higher numbers per list once multi-services has been implemented.
|
||||
|
||||
IEnumerable<Task> tasks = shows
|
||||
.Select(x => x.First())
|
||||
.Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken));
|
||||
foreach (Task[] showTasks in tasks.BatchBy(30))
|
||||
foreach (Task[] showTasks in tasks.BatchBy(_parallelTasks))
|
||||
await Task.WhenAll(showTasks);
|
||||
|
||||
tasks = shows
|
||||
.SelectMany(x => x.Skip(1))
|
||||
.Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken));
|
||||
foreach (Task[] episodeTasks in tasks.BatchBy(50))
|
||||
foreach (Task[] episodeTasks in tasks.BatchBy(_parallelTasks * 2))
|
||||
await Task.WhenAll(episodeTasks);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
"ConnectionStrings": {
|
||||
"Database": "Server=127.0.0.1; Port=5432; Database=kyooDB; User Id=kyoo; Password=kyooPassword; Pooling=true; MaxPoolSize=95; Timeout=30;"
|
||||
},
|
||||
"parallelTasks": "40",
|
||||
|
||||
"scheduledTasks": {
|
||||
"scan": "24:00:00"
|
||||
|
Loading…
x
Reference in New Issue
Block a user