When upgrading Kavita, clear out existing Github cache.
This commit is contained in:
parent
fd1a58f438
commit
a2f6dfa7bf
2 changed files with 31 additions and 4 deletions
|
|
@ -52,6 +52,7 @@ public interface IVersionUpdaterService
|
|||
Task PushUpdate(UpdateNotificationDto update);
|
||||
Task<IList<UpdateNotificationDto>> GetAllReleases(int count = 0);
|
||||
Task<int> GetNumberOfReleasesBehind(bool stableOnly = false);
|
||||
void BustGithubCache();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -384,7 +385,7 @@ public partial class VersionUpdaterService : IVersionUpdaterService
|
|||
if (DateTime.UtcNow - fileInfo.LastWriteTimeUtc <= CacheDuration)
|
||||
{
|
||||
var cachedData = await File.ReadAllTextAsync(_cacheLatestReleaseFilePath);
|
||||
return System.Text.Json.JsonSerializer.Deserialize<UpdateNotificationDto>(cachedData);
|
||||
return JsonSerializer.Deserialize<UpdateNotificationDto>(cachedData);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -407,7 +408,7 @@ public partial class VersionUpdaterService : IVersionUpdaterService
|
|||
{
|
||||
try
|
||||
{
|
||||
var json = System.Text.Json.JsonSerializer.Serialize(update, JsonOptions);
|
||||
var json = JsonSerializer.Serialize(update, JsonOptions);
|
||||
await File.WriteAllTextAsync(_cacheLatestReleaseFilePath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -446,6 +447,21 @@ public partial class VersionUpdaterService : IVersionUpdaterService
|
|||
.Count(u => u.IsReleaseNewer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the Github cache
|
||||
/// </summary>
|
||||
public void BustGithubCache()
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(_cacheFilePath);
|
||||
File.Delete(_cacheLatestReleaseFilePath);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to clear Github cache");
|
||||
}
|
||||
}
|
||||
|
||||
private UpdateNotificationDto? CreateDto(GithubReleaseMetadata? update)
|
||||
{
|
||||
if (update == null || string.IsNullOrEmpty(update.Tag_Name)) return null;
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ public class Startup
|
|||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IBackgroundJobClient backgroundJobs, IWebHostEnvironment env,
|
||||
IHostApplicationLifetime applicationLifetime, IServiceProvider serviceProvider, ICacheService cacheService,
|
||||
IDirectoryService directoryService, IUnitOfWork unitOfWork, IBackupService backupService, IImageService imageService)
|
||||
IDirectoryService directoryService, IUnitOfWork unitOfWork, IBackupService backupService, IImageService imageService, IVersionUpdaterService versionService)
|
||||
{
|
||||
|
||||
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
|
||||
|
|
@ -235,9 +235,10 @@ public class Startup
|
|||
// Apply all migrations on startup
|
||||
var dataContext = serviceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
|
||||
logger.LogInformation("Running Migrations");
|
||||
|
||||
#region Migrations
|
||||
|
||||
// v0.7.9
|
||||
await MigrateUserLibrarySideNavStream.Migrate(unitOfWork, dataContext, logger);
|
||||
|
||||
|
|
@ -289,13 +290,23 @@ public class Startup
|
|||
await ManualMigrateScrobbleSpecials.Migrate(dataContext, logger);
|
||||
await ManualMigrateScrobbleEventGen.Migrate(dataContext, logger);
|
||||
|
||||
#endregion
|
||||
|
||||
// Update the version in the DB after all migrations are run
|
||||
var installVersion = await unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.InstallVersion);
|
||||
var isVersionDifferent = installVersion.Value != BuildInfo.Version.ToString();
|
||||
installVersion.Value = BuildInfo.Version.ToString();
|
||||
unitOfWork.SettingsRepository.Update(installVersion);
|
||||
await unitOfWork.CommitAsync();
|
||||
|
||||
logger.LogInformation("Running Migrations - complete");
|
||||
|
||||
if (isVersionDifferent)
|
||||
{
|
||||
// Clear the Github cache so update stuff shows correctly
|
||||
versionService.BustGithubCache();
|
||||
}
|
||||
|
||||
}).GetAwaiter()
|
||||
.GetResult();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue