No more wasteful XML writes

update only the XML file corresponding to the analyzed mode
This commit is contained in:
rlauuzo 2024-04-20 16:21:20 +02:00 committed by GitHub
parent 12bed0560c
commit a9bf646421
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -226,6 +226,52 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
}
}
/// <summary>
/// Save timestamps to disk.
/// </summary>
/// <param name="mode">Mode.</param>
public void SaveTimestamps(AnalysisMode mode)
{
lock (_serializationLock)
{
var introList = new List<Intro>();
// Serialize intros
if (mode == AnalysisMode.Introduction)
{
foreach (var intro in Instance!.Intros)
{
introList.Add(intro.Value);
}
try
{
XmlSerializationHelper.SerializeToXml(introList, _introPath);
}
catch (Exception e)
{
_logger.LogError("SaveTimestamps intros {Message}", e.Message);
}
}
else if (mode == AnalysisMode.Credits)
{
foreach (var intro in Instance.Credits)
{
introList.Add(intro.Value);
}
try
{
XmlSerializationHelper.SerializeToXml(introList, _creditsPath);
}
catch (Exception e)
{
_logger.LogError("SaveTimestamps credits {Message}", e.Message);
}
}
}
}
/// <summary>
/// Restore previous analysis results from disk.
/// </summary>
@ -346,7 +392,7 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
}
}
Instance!.SaveTimestamps();
Instance!.SaveTimestamps(mode);
}
}