From 7c08978cc85414fabb3b0cc8f8a007e24b62604c Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Thu, 3 Aug 2023 17:06:32 +0200 Subject: [PATCH] Reduce github api calls in hashtable syncing from 2 to 1 --- Obsidian/Services/HashtableService.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Obsidian/Services/HashtableService.cs b/Obsidian/Services/HashtableService.cs index f412674..4dcb949 100644 --- a/Obsidian/Services/HashtableService.cs +++ b/Obsidian/Services/HashtableService.cs @@ -36,6 +36,8 @@ public class HashtableService { private const string BIN_HASHES_PATH = "hashes/hashes.binhashes.txt"; private const string BIN_OBJECTS_PATH = "hashes/hashes.binentries.txt"; + private IReadOnlyList cdragonRepositoryContent; + public HashtableService(Config config) { this.Config = config; } @@ -83,14 +85,14 @@ private async Task SyncHashtables(HttpClient client) { Log.Information("Syncing WAD hashtables"); GitHubClient github = new(new ProductHeaderValue("Obsidian")); - IReadOnlyList content = await github.Repository.Content.GetAllContents( + this.cdragonRepositoryContent ??= await github.Repository.Content.GetAllContents( "CommunityDragon", "CDTB", "cdragontoolbox" ); - RepositoryContent gameHashesContent = GetRepositoryContent(content, "hashes.game.txt"); - RepositoryContent lcuHashesContent = GetRepositoryContent(content, "hashes.lcu.txt"); + RepositoryContent gameHashesContent = GetRepositoryContent(this.cdragonRepositoryContent, "hashes.game.txt"); + RepositoryContent lcuHashesContent = GetRepositoryContent(this.cdragonRepositoryContent, "hashes.lcu.txt"); this.Config.GameHashesChecksum = await SyncHashtable( client, @@ -112,16 +114,16 @@ private async Task SyncBinHashtables(HttpClient client) { Log.Information("Syncing BIN hashtables"); GitHubClient github = new(new ProductHeaderValue("Obsidian")); - IReadOnlyList content = await github.Repository.Content.GetAllContents( + this.cdragonRepositoryContent ??= await github.Repository.Content.GetAllContents( "CommunityDragon", "CDTB", "cdragontoolbox" ); - RepositoryContent fieldsContent = GetRepositoryContent(content, "hashes.binfields.txt"); - RepositoryContent typesContent = GetRepositoryContent(content, "hashes.bintypes.txt"); - RepositoryContent hashesContent = GetRepositoryContent(content, "hashes.binhashes.txt"); - RepositoryContent entriesContent = GetRepositoryContent(content, "hashes.binentries.txt"); + RepositoryContent fieldsContent = GetRepositoryContent(this.cdragonRepositoryContent, "hashes.binfields.txt"); + RepositoryContent typesContent = GetRepositoryContent(this.cdragonRepositoryContent, "hashes.bintypes.txt"); + RepositoryContent hashesContent = GetRepositoryContent(this.cdragonRepositoryContent, "hashes.binhashes.txt"); + RepositoryContent entriesContent = GetRepositoryContent(this.cdragonRepositoryContent, "hashes.binentries.txt"); this.Config.BinFieldsHashesChecksum = await SyncHashtable( client,