Skip to content

Commit

Permalink
Merge pull request #1216 from ShokoAnime/cached_tmdb
Browse files Browse the repository at this point in the history
Cache core tmdb tables
  • Loading branch information
revam authored Jan 5, 2025
2 parents 9dfedb0 + 61edd15 commit 23061b5
Show file tree
Hide file tree
Showing 52 changed files with 247 additions and 283 deletions.
2 changes: 2 additions & 0 deletions Shoko.Server/Providers/TMDB/TmdbImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Shoko.Plugin.Abstractions.Extensions;
using Shoko.Server.Models.TMDB;
using Shoko.Server.Repositories.Cached;
using Shoko.Server.Repositories.Cached.AniDB;
using Shoko.Server.Repositories.Cached.TMDB;
using Shoko.Server.Repositories.Direct;
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs.TMDB;
Expand Down
2 changes: 2 additions & 0 deletions Shoko.Server/Providers/TMDB/TmdbLinkingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Shoko.Server.Models.CrossReference;
using Shoko.Server.Models.TMDB;
using Shoko.Server.Repositories.Cached;
using Shoko.Server.Repositories.Cached.AniDB;
using Shoko.Server.Repositories.Cached.TMDB;
using Shoko.Server.Repositories.Direct;
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs.TMDB;
Expand Down
4 changes: 4 additions & 0 deletions Shoko.Server/Providers/TMDB/TmdbMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
using Shoko.Server.Models.Interfaces;
using Shoko.Server.Models.TMDB;
using Shoko.Server.Repositories.Cached;
using Shoko.Server.Repositories.Cached.TMDB;
using Shoko.Server.Repositories.Direct;
using Shoko.Server.Repositories.Direct.TMDB;
using Shoko.Server.Repositories.Direct.TMDB.Optional;
using Shoko.Server.Repositories.Direct.TMDB.Text;
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs.TMDB;
using Shoko.Server.Server;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Server.Databases;
using Shoko.Server.Models;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_AnimeRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<SVR_AniDB_Anime, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Server.Databases;
using Shoko.Server.Models.AniDB;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_Anime_CharacterRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_Anime_Character, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Server.Databases;
using Shoko.Server.Models.AniDB;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_Anime_Character_CreatorRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_Anime_Character_Creator, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Models.Enums;
using Shoko.Plugin.Abstractions.Enums;
using Shoko.Server.Databases;
using Shoko.Server.Models.AniDB;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_Anime_PreferredImageRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_Anime_PreferredImage, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Models.Server;
using Shoko.Server.Databases;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_Anime_TagRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_Anime_Tag, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Commons.Properties;
using Shoko.Server.Databases;
using Shoko.Server.Models;
using Shoko.Server.Server;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_Anime_TitleRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<SVR_AniDB_Anime_Title, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Commons.Extensions;
using Shoko.Server.Databases;
using Shoko.Server.Models.AniDB;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_CharacterRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_Character, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#nullable enable
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Server.Models.AniDB;
using Shoko.Server.Databases;
using Shoko.Server.Models.AniDB;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_CreatorRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_Creator, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
Expand All @@ -7,8 +8,7 @@
using Shoko.Server.Databases;
using Shoko.Server.Models;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_EpisodeRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<SVR_AniDB_Episode, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
Expand All @@ -6,8 +7,7 @@
using Shoko.Server.Databases;
using Shoko.Server.Models.AniDB;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_Episode_PreferredImageRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_Episode_PreferredImage, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Server.Databases;
using Shoko.Server.Models;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_Episode_TitleRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<SVR_AniDB_Episode_Title, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NLog;
using NutzCode.InMemoryIndex;
using Shoko.Server.Databases;
using Shoko.Server.Models;
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs.Actions;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_FileRepository(ILogger<AniDB_FileRepository> logger, JobFactory jobFactory, DatabaseFactory databaseFactory) : BaseCachedRepository<SVR_AniDB_File, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#pragma warning disable CS8618
#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_ReleaseGroupRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_ReleaseGroup, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Collections.Generic;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Commons.Extensions;
using Shoko.Models.Server;
using Shoko.Server.Databases;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_TagRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<AniDB_Tag, int>(databaseFactory)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
Expand All @@ -8,8 +8,7 @@
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs.Actions;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.AniDB;

public class AniDB_VoteRepository : BaseCachedRepository<AniDB_Vote, int>
{
Expand Down
42 changes: 42 additions & 0 deletions Shoko.Server/Repositories/Cached/TMDB/TMDB_EpisodeRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Server.Databases;
using Shoko.Server.Models.TMDB;

namespace Shoko.Server.Repositories.Cached.TMDB;

public class TMDB_EpisodeRepository : BaseCachedRepository<TMDB_Episode, int>
{
protected override int SelectKey(TMDB_Episode entity) => entity.Id;
private PocoIndex<int, TMDB_Episode, int> _showIDs = null!;
private PocoIndex<int, TMDB_Episode, int> _seasonIDs = null!;
private PocoIndex<int, TMDB_Episode, int> _episodeIDs = null!;

public override void PopulateIndexes()
{
_showIDs = Cache.CreateIndex(a => a.TmdbShowID);
_seasonIDs = Cache.CreateIndex(a => a.TmdbSeasonID);
_episodeIDs = Cache.CreateIndex(a => a.TmdbEpisodeID);
}

public IReadOnlyList<TMDB_Episode> GetByTmdbShowID(int showId)
{
return _showIDs.GetMultiple(showId).OrderBy(a => a.EpisodeNumber).ToList();
}

public IReadOnlyList<TMDB_Episode> GetByTmdbSeasonID(int seasonId)
{
return _seasonIDs.GetMultiple(seasonId).OrderBy(a => a.EpisodeNumber).ToList();
}

public TMDB_Episode? GetByTmdbEpisodeID(int episodeId)
{
return _episodeIDs.GetOne(episodeId);
}

public TMDB_EpisodeRepository(DatabaseFactory databaseFactory) : base(databaseFactory)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
Expand All @@ -6,8 +7,7 @@
using Shoko.Server.Models.TMDB;
using Shoko.Server.Server;

#nullable enable
namespace Shoko.Server.Repositories.Cached;
namespace Shoko.Server.Repositories.Cached.TMDB;

public class TMDB_ImageRepository(DatabaseFactory databaseFactory) : BaseCachedRepository<TMDB_Image, int>(databaseFactory)
{
Expand Down
37 changes: 37 additions & 0 deletions Shoko.Server/Repositories/Cached/TMDB/TMDB_MovieRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Server.Databases;
using Shoko.Server.Models.TMDB;

namespace Shoko.Server.Repositories.Cached.TMDB;

public class TMDB_MovieRepository : BaseCachedRepository<TMDB_Movie, int>
{
protected override int SelectKey(TMDB_Movie entity) => entity.Id;
private PocoIndex<int, TMDB_Movie, int> _movieIDs = null!;
private PocoIndex<int, TMDB_Movie, int?> _collectionIDs = null!;

public override void PopulateIndexes()
{
_movieIDs = Cache.CreateIndex(a => a.TmdbMovieID);
_collectionIDs = Cache.CreateIndex(a => a.TmdbCollectionID);
}

public TMDB_Movie? GetByTmdbMovieID(int tmdbMovieId)
{
return _movieIDs.GetOne(tmdbMovieId);
}

public IReadOnlyList<TMDB_Movie> GetByTmdbCollectionID(int tmdbCollectionId)
{
return _collectionIDs.GetMultiple(tmdbCollectionId).OrderBy(a => a.EnglishTitle)
.ThenBy(a => a.TmdbMovieID)
.ToList();
}

public TMDB_MovieRepository(DatabaseFactory databaseFactory) : base(databaseFactory)
{
}
}
38 changes: 38 additions & 0 deletions Shoko.Server/Repositories/Cached/TMDB/TMDB_SeasonRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#nullable enable
using System.Collections.Generic;
using System.Linq;
using NutzCode.InMemoryIndex;
using Shoko.Server.Databases;
using Shoko.Server.Models.TMDB;

namespace Shoko.Server.Repositories.Cached.TMDB;

public class TMDB_SeasonRepository : BaseCachedRepository<TMDB_Season, int>
{
protected override int SelectKey(TMDB_Season entity) => entity.Id;
private PocoIndex<int, TMDB_Season, int> _showIDs = null!;
private PocoIndex<int, TMDB_Season, int> _seasonIDs = null!;

public override void PopulateIndexes()
{
_showIDs = Cache.CreateIndex(a => a.TmdbShowID);
_seasonIDs = Cache.CreateIndex(a => a.TmdbSeasonID);
}

public IReadOnlyList<TMDB_Season> GetByTmdbShowID(int tmdbShowId)
{
return _showIDs.GetMultiple(tmdbShowId)
.OrderBy(e => e.SeasonNumber == 0)
.ThenBy(e => e.SeasonNumber)
.ToList();
}

public TMDB_Season? GetByTmdbSeasonID(int tmdbSeasonId)
{
return _seasonIDs.GetOne(tmdbSeasonId);
}

public TMDB_SeasonRepository(DatabaseFactory databaseFactory) : base(databaseFactory)
{
}
}
Loading

0 comments on commit 23061b5

Please sign in to comment.