mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 15:14:41 +00:00
STD: Perform Save() of GlobalCache in background
We don't need to slow down the process with I/O there, at all. ASF already handles its own database like that.
This commit is contained in:
parent
cc1eb6bee2
commit
e2c7671f00
2 changed files with 24 additions and 24 deletions
|
@ -91,7 +91,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
return globalCache;
|
||||
}
|
||||
|
||||
internal async Task OnPICSChanges(uint currentChangeNumber, IReadOnlyCollection<KeyValuePair<uint, SteamApps.PICSChangesCallback.PICSChangeData>> appChanges) {
|
||||
internal void OnPICSChanges(uint currentChangeNumber, IReadOnlyCollection<KeyValuePair<uint, SteamApps.PICSChangesCallback.PICSChangeData>> appChanges) {
|
||||
if (currentChangeNumber == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(currentChangeNumber));
|
||||
}
|
||||
|
@ -117,10 +117,10 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
ASF.ArchiLogger.LogGenericTrace($"App needs refresh: {appID}");
|
||||
}
|
||||
|
||||
await Save().ConfigureAwait(false);
|
||||
Utilities.InBackground(Save);
|
||||
}
|
||||
|
||||
internal async Task OnPICSChangesRestart(uint currentChangeNumber) {
|
||||
internal void OnPICSChangesRestart(uint currentChangeNumber) {
|
||||
if (currentChangeNumber == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(currentChangeNumber));
|
||||
}
|
||||
|
@ -132,16 +132,15 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
ASF.ArchiLogger.LogGenericDebug($"RESET {LastChangeNumber} => {currentChangeNumber}");
|
||||
|
||||
LastChangeNumber = currentChangeNumber;
|
||||
|
||||
AppChangeNumbers.Clear();
|
||||
|
||||
await Save().ConfigureAwait(false);
|
||||
Utilities.InBackground(Save);
|
||||
}
|
||||
|
||||
internal bool ShouldRefreshAppInfo(uint appID) => !AppChangeNumbers.ContainsKey(appID);
|
||||
internal bool ShouldRefreshDepotKey(uint depotID) => !DepotKeys.ContainsKey(depotID);
|
||||
|
||||
internal async Task UpdateAppChangeNumbers(IReadOnlyCollection<KeyValuePair<uint, uint>> appChangeNumbers) {
|
||||
internal void UpdateAppChangeNumbers(IReadOnlyCollection<KeyValuePair<uint, uint>> appChangeNumbers) {
|
||||
if (appChangeNumbers == null) {
|
||||
throw new ArgumentNullException(nameof(appChangeNumbers));
|
||||
}
|
||||
|
@ -158,11 +157,11 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
}
|
||||
|
||||
if (save) {
|
||||
await Save().ConfigureAwait(false);
|
||||
Utilities.InBackground(Save);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task UpdateAppTokens(IReadOnlyCollection<KeyValuePair<uint, ulong>> appTokens, IReadOnlyCollection<uint> publicAppIDs) {
|
||||
internal void UpdateAppTokens(IReadOnlyCollection<KeyValuePair<uint, ulong>> appTokens, IReadOnlyCollection<uint> publicAppIDs) {
|
||||
if (appTokens == null) {
|
||||
throw new ArgumentNullException(nameof(appTokens));
|
||||
}
|
||||
|
@ -192,11 +191,11 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
}
|
||||
|
||||
if (save) {
|
||||
await Save().ConfigureAwait(false);
|
||||
Utilities.InBackground(Save);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task UpdateDepotKeys(ICollection<SteamApps.DepotKeyCallback> depotKeyResults) {
|
||||
internal void UpdateDepotKeys(ICollection<SteamApps.DepotKeyCallback> depotKeyResults) {
|
||||
if (depotKeyResults == null) {
|
||||
throw new ArgumentNullException(nameof(depotKeyResults));
|
||||
}
|
||||
|
@ -219,11 +218,11 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
}
|
||||
|
||||
if (save) {
|
||||
await Save().ConfigureAwait(false);
|
||||
Utilities.InBackground(Save);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task UpdatePackageTokens(IReadOnlyCollection<KeyValuePair<uint, ulong>> packageTokens) {
|
||||
internal void UpdatePackageTokens(IReadOnlyCollection<KeyValuePair<uint, ulong>> packageTokens) {
|
||||
if (packageTokens == null) {
|
||||
throw new ArgumentNullException(nameof(packageTokens));
|
||||
}
|
||||
|
@ -240,11 +239,11 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
}
|
||||
|
||||
if (save) {
|
||||
await Save().ConfigureAwait(false);
|
||||
Utilities.InBackground(Save);
|
||||
}
|
||||
}
|
||||
|
||||
internal async Task UpdateSubmittedData(IReadOnlyDictionary<uint, ulong> apps, IReadOnlyDictionary<uint, ulong> packages, IReadOnlyDictionary<uint, string> depots) {
|
||||
internal void UpdateSubmittedData(IReadOnlyDictionary<uint, ulong> apps, IReadOnlyDictionary<uint, ulong> packages, IReadOnlyDictionary<uint, string> depots) {
|
||||
if (apps == null) {
|
||||
throw new ArgumentNullException(nameof(apps));
|
||||
}
|
||||
|
@ -269,7 +268,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
SubmittedDepots[depotID] = key;
|
||||
}
|
||||
|
||||
await Save().ConfigureAwait(false);
|
||||
Utilities.InBackground(Save);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
|
||||
public override void OnLoaded() { }
|
||||
|
||||
public async void OnPICSChanges(uint currentChangeNumber, IReadOnlyDictionary<uint, SteamApps.PICSChangesCallback.PICSChangeData> appChanges, IReadOnlyDictionary<uint, SteamApps.PICSChangesCallback.PICSChangeData> packageChanges) {
|
||||
public void OnPICSChanges(uint currentChangeNumber, IReadOnlyDictionary<uint, SteamApps.PICSChangesCallback.PICSChangeData> appChanges, IReadOnlyDictionary<uint, SteamApps.PICSChangesCallback.PICSChangeData> packageChanges) {
|
||||
if (currentChangeNumber == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(currentChangeNumber));
|
||||
}
|
||||
|
@ -182,10 +182,10 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
throw new InvalidOperationException(nameof(GlobalCache));
|
||||
}
|
||||
|
||||
await GlobalCache.OnPICSChanges(currentChangeNumber, appChanges).ConfigureAwait(false);
|
||||
GlobalCache.OnPICSChanges(currentChangeNumber, appChanges);
|
||||
}
|
||||
|
||||
public async void OnPICSChangesRestart(uint currentChangeNumber) {
|
||||
public void OnPICSChangesRestart(uint currentChangeNumber) {
|
||||
if (currentChangeNumber == 0) {
|
||||
throw new ArgumentOutOfRangeException(nameof(currentChangeNumber));
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
throw new InvalidOperationException(nameof(GlobalCache));
|
||||
}
|
||||
|
||||
await GlobalCache.OnPICSChangesRestart(currentChangeNumber).ConfigureAwait(false);
|
||||
GlobalCache.OnPICSChangesRestart(currentChangeNumber);
|
||||
}
|
||||
|
||||
private static async void OnLicenseList(Bot bot, SteamApps.LicenseListCallback callback) {
|
||||
|
@ -220,7 +220,8 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
|
||||
Dictionary<uint, ulong> packageTokens = callback.LicenseList.GroupBy(license => license.PackageID).ToDictionary(group => group.Key, group => group.OrderByDescending(license => license.TimeCreated).First().AccessToken);
|
||||
|
||||
await GlobalCache.UpdatePackageTokens(packageTokens).ConfigureAwait(false);
|
||||
GlobalCache.UpdatePackageTokens(packageTokens);
|
||||
|
||||
await Refresh(bot, packageTokens.Keys).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
@ -313,7 +314,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
|
||||
appIDsThisRound.Clear();
|
||||
|
||||
await GlobalCache.UpdateAppTokens(response.AppTokens, response.AppTokensDenied).ConfigureAwait(false);
|
||||
GlobalCache.UpdateAppTokens(response.AppTokens, response.AppTokensDenied);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,7 +377,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
}
|
||||
}
|
||||
|
||||
await GlobalCache.UpdateAppChangeNumbers(appChangeNumbers).ConfigureAwait(false);
|
||||
GlobalCache.UpdateAppChangeNumbers(appChangeNumbers);
|
||||
|
||||
if (depotTasks.Count > 0) {
|
||||
bot.ArchiLogger.LogGenericInfo($"Retrieving {depotTasks.Count} depot keys...");
|
||||
|
@ -393,7 +394,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
|
||||
bot.ArchiLogger.LogGenericInfo($"Finished retrieving {depotTasks.Count} depot keys.");
|
||||
|
||||
await GlobalCache.UpdateDepotKeys(results).ConfigureAwait(false);
|
||||
GlobalCache.UpdateDepotKeys(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -483,7 +484,7 @@ namespace ArchiSteamFarm.OfficialPlugins.SteamTokenDumper {
|
|||
|
||||
ASF.ArchiLogger.LogGenericInfo($"Data successfully submitted. Newly registered apps/subs/depots: {response.Content.Data.NewAppsCount}/{response.Content.Data.NewSubsCount}/{response.Content.Data.NewDepotsCount}.");
|
||||
|
||||
await GlobalCache.UpdateSubmittedData(appTokens, packageTokens, depotKeys).ConfigureAwait(false);
|
||||
GlobalCache.UpdateSubmittedData(appTokens, packageTokens, depotKeys);
|
||||
} finally {
|
||||
SubmissionSemaphore.Release();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue