Example #1
0
        public async Task <ModInfo> GetModInfo(string GameName, long ModId)
        {
            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await _sql.GetNexusModInfoString(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await NexusApiClient.Get(Request.Headers["apikey"].FirstOrDefault());

                result = await api.GetModInfo(game, ModId, false);

                await _sql.AddNexusModInfo(game, ModId, DateTime.UtcNow, result);


                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }

            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
Example #2
0
        public async Task <ModInfo> GetModInfo(string GameName, long ModId)
        {
            var game   = GameRegistry.GetByFuzzyName(GameName).Game;
            var result = await _sql.GetNexusModInfoString(game, ModId);

            string method = "CACHED";

            if (result == null)
            {
                var api = await GetClient();

                result = await api.GetModInfo(game, ModId, false);

                await _sql.AddNexusModInfo(game, ModId, result.updated_time, result);


                method = "NOT_CACHED";
                Interlocked.Increment(ref ForwardCount);
            }
            else
            {
                Interlocked.Increment(ref CachedCount);
            }

            Response.Headers.Add("x-cache-result", method);
            return(result);
        }
Example #3
0
        public async Task UpdateNexusCacheRSS()
        {
            using var _ = _logger.BeginScope("Nexus Update via RSS");
            _logger.Log(LogLevel.Information, "Starting");

            var results = await NexusUpdatesFeeds.GetUpdates();

            NexusApiClient client  = null;
            long           updated = 0;

            foreach (var result in results)
            {
                try
                {
                    var purgedMods =
                        await _sql.DeleteNexusModFilesUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                    var purgedFiles =
                        await _sql.DeleteNexusModInfosUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                    var totalPurged = purgedFiles + purgedMods;
                    if (totalPurged > 0)
                    {
                        _logger.Log(LogLevel.Information, $"Purged {totalPurged} cache items {result.Game} {result.ModId} {result.TimeStamp}");
                    }

                    if (await _sql.GetNexusModInfoString(result.Game, result.ModId) != null)
                    {
                        continue;
                    }

                    // Lazily create the client
                    client ??= await NexusApiClient.Get();

                    // Cache the info
                    var files = await client.GetModFiles(result.Game, result.ModId, false);

                    await _sql.AddNexusModFiles(result.Game, result.ModId, result.TimeStamp, files);

                    var modInfo = await client.GetModInfo(result.Game, result.ModId, useCache : false);

                    await _sql.AddNexusModInfo(result.Game, result.ModId, result.TimeStamp, modInfo);

                    updated++;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Failed Nexus update for {result.Game} - {result.ModId} - {result.TimeStamp}");
                }
            }

            if (updated > 0)
            {
                _logger.Log(LogLevel.Information, $"Primed {updated} nexus cache entries");
            }

            _globalInformation.LastNexusSyncUTC = DateTime.UtcNow;
        }
Example #4
0
        public static async Task <long> UpdateNexusCacheFast(SqlService sql)
        {
            var results = await NexusUpdatesFeeds.GetUpdates();

            NexusApiClient client  = null;
            long           updated = 0;

            foreach (var result in results)
            {
                var purgedMods = await sql.DeleteNexusModFilesUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                var purgedFiles = await sql.DeleteNexusModInfosUpdatedBeforeDate(result.Game, result.ModId, result.TimeStamp);

                var totalPurged = purgedFiles + purgedMods;
                if (totalPurged > 0)
                {
                    Utils.Log($"Purged {totalPurged} cache items");
                }

                if (await sql.GetNexusModInfoString(result.Game, result.ModId) != null)
                {
                    continue;
                }

                // Lazily create the client
                client ??= await NexusApiClient.Get();

                // Cache the info
                var files = await client.GetModFiles(result.Game, result.ModId, false);

                await sql.AddNexusModFiles(result.Game, result.ModId, result.TimeStamp, files);

                var modInfo = await client.GetModInfo(result.Game, result.ModId);

                await sql.AddNexusModInfo(result.Game, result.ModId, result.TimeStamp, modInfo);

                updated++;
            }

            if (updated > 0)
            {
                Utils.Log($"Primed {updated} nexus cache entries");
            }

            LastNexusSync = DateTime.Now;
            return(updated);
        }