mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Centalise and prefix all ArchiveModelManager database logging
This commit is contained in:
@ -110,7 +110,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
validateOnlineIds(beatmapSet);
|
validateOnlineIds(beatmapSet);
|
||||||
|
|
||||||
await Task.WhenAll(beatmapSet.Beatmaps.Select(b => updateQueue.Perform(b, cancellationToken)).ToArray());
|
await updateQueue.Perform(beatmapSet, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PreImport(BeatmapSetInfo beatmapSet)
|
protected override void PreImport(BeatmapSetInfo beatmapSet)
|
||||||
@ -127,7 +127,7 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
Delete(existingOnlineId);
|
Delete(existingOnlineId);
|
||||||
beatmaps.PurgeDeletable(s => s.ID == existingOnlineId.ID);
|
beatmaps.PurgeDeletable(s => s.ID == existingOnlineId.ID);
|
||||||
Logger.Log($"Found existing beatmap set with same OnlineBeatmapSetID ({beatmapSet.OnlineBeatmapSetID}). It has been purged.", LoggingTarget.Database);
|
LogForModel(beatmapSet, $"Found existing beatmap set with same OnlineBeatmapSetID ({beatmapSet.OnlineBeatmapSetID}). It has been purged.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -433,23 +433,29 @@ namespace osu.Game.Beatmaps
|
|||||||
this.api = api;
|
this.api = api;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task Perform(BeatmapInfo beatmap, CancellationToken cancellationToken)
|
public async Task Perform(BeatmapSetInfo beatmapSet, CancellationToken cancellationToken)
|
||||||
=> Task.Factory.StartNew(() => perform(beatmap, cancellationToken), cancellationToken, TaskCreationOptions.HideScheduler, updateScheduler);
|
|
||||||
|
|
||||||
private void perform(BeatmapInfo beatmap, CancellationToken cancellation)
|
|
||||||
{
|
{
|
||||||
cancellation.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (api?.State != APIState.Online)
|
if (api?.State != APIState.Online)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Logger.Log("Attempting online lookup for the missing values...", LoggingTarget.Database);
|
LogForModel(beatmapSet, "Performing online lookups...");
|
||||||
|
await Task.WhenAll(beatmapSet.Beatmaps.Select(b => Perform(beatmapSet, b, cancellationToken)).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: expose this when we need to do individual difficulty lookups.
|
||||||
|
protected Task Perform(BeatmapSetInfo beatmapSet, BeatmapInfo beatmap, CancellationToken cancellationToken)
|
||||||
|
=> Task.Factory.StartNew(() => perform(beatmapSet, beatmap), cancellationToken, TaskCreationOptions.HideScheduler, updateScheduler);
|
||||||
|
|
||||||
|
private void perform(BeatmapSetInfo set, BeatmapInfo beatmap)
|
||||||
|
{
|
||||||
|
if (api?.State != APIState.Online)
|
||||||
|
return;
|
||||||
|
|
||||||
var req = new GetBeatmapRequest(beatmap);
|
var req = new GetBeatmapRequest(beatmap);
|
||||||
|
|
||||||
req.Success += res =>
|
req.Success += res =>
|
||||||
{
|
{
|
||||||
Logger.Log($"Successfully mapped to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.", LoggingTarget.Database);
|
LogForModel(set, $"Online retrieval mapped {beatmap} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
|
||||||
|
|
||||||
beatmap.Status = res.Status;
|
beatmap.Status = res.Status;
|
||||||
beatmap.BeatmapSet.Status = res.BeatmapSet.Status;
|
beatmap.BeatmapSet.Status = res.BeatmapSet.Status;
|
||||||
@ -457,7 +463,7 @@ namespace osu.Game.Beatmaps
|
|||||||
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
||||||
};
|
};
|
||||||
|
|
||||||
req.Failure += e => { Logger.Log($"Failed ({e})", LoggingTarget.Database); };
|
req.Failure += e => { LogForModel(set, $"Online retrieval failed for {beatmap}", e); };
|
||||||
|
|
||||||
// intentionally blocking to limit web request concurrency
|
// intentionally blocking to limit web request concurrency
|
||||||
req.Perform(api);
|
req.Perform(api);
|
||||||
|
@ -173,7 +173,7 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Error(e, $@"Could not import ({Path.GetFileName(path)})");
|
Logger.Error(e, $@"Could not import ({Path.GetFileName(path)})", LoggingTarget.Database);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -227,7 +227,7 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Error(e, $@"Could not delete original file after import ({Path.GetFileName(path)})");
|
LogForModel(import, $@"Could not delete original file after import ({Path.GetFileName(path)})", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return import;
|
return import;
|
||||||
@ -247,7 +247,7 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
TModel model;
|
TModel model = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -263,7 +263,7 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger.Error(e, $"Model creation of {archive.Name} failed.", LoggingTarget.Database);
|
LogForModel(model, $"Model creation of {archive.Name} failed.", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,6 +277,16 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract string[] HashableFileTypes { get; }
|
protected abstract string[] HashableFileTypes { get; }
|
||||||
|
|
||||||
|
protected static void LogForModel(TModel model, string message, Exception e = null)
|
||||||
|
{
|
||||||
|
string prefix = $"[{(model?.Hash ?? "?????").Substring(0, 5)}]";
|
||||||
|
|
||||||
|
if (e != null)
|
||||||
|
Logger.Error(e, $"{prefix} {message}", LoggingTarget.Database);
|
||||||
|
else
|
||||||
|
Logger.Log($"{prefix} {message}", LoggingTarget.Database);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a SHA-2 hash from the provided archive based on file content of all files matching <see cref="HashableFileTypes"/>.
|
/// Create a SHA-2 hash from the provided archive based on file content of all files matching <see cref="HashableFileTypes"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -308,14 +318,14 @@ namespace osu.Game.Database
|
|||||||
if (!Delete(item))
|
if (!Delete(item))
|
||||||
{
|
{
|
||||||
// We may have not yet added the model to the underlying table, but should still clean up files.
|
// We may have not yet added the model to the underlying table, but should still clean up files.
|
||||||
Logger.Log($"Dereferencing files for incomplete import of {item}.", LoggingTarget.Database);
|
LogForModel(item, "Dereferencing files for incomplete import.");
|
||||||
Files.Dereference(item.Files.Select(f => f.FileInfo).ToArray());
|
Files.Dereference(item.Files.Select(f => f.FileInfo).ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Logger.Log($"Importing {item}...", LoggingTarget.Database);
|
LogForModel(item, "Beginning import...");
|
||||||
|
|
||||||
item.Files = archive != null ? createFileInfos(archive, Files) : new List<TFileModel>();
|
item.Files = archive != null ? createFileInfos(archive, Files) : new List<TFileModel>();
|
||||||
|
|
||||||
@ -334,7 +344,7 @@ namespace osu.Game.Database
|
|||||||
if (CanUndelete(existing, item))
|
if (CanUndelete(existing, item))
|
||||||
{
|
{
|
||||||
Undelete(existing);
|
Undelete(existing);
|
||||||
Logger.Log($"Found existing {humanisedModelName} for {item} (ID {existing.ID}). Skipping import.", LoggingTarget.Database);
|
LogForModel(item, $"Found existing {humanisedModelName} for {item} (ID {existing.ID}) – skipping import.");
|
||||||
handleEvent(() => ItemAdded?.Invoke(existing, true));
|
handleEvent(() => ItemAdded?.Invoke(existing, true));
|
||||||
|
|
||||||
// existing item will be used; rollback new import and exit early.
|
// existing item will be used; rollback new import and exit early.
|
||||||
@ -342,11 +352,9 @@ namespace osu.Game.Database
|
|||||||
flushEvents(true);
|
flushEvents(true);
|
||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
Delete(existing);
|
||||||
Delete(existing);
|
ModelStore.PurgeDeletable(s => s.ID == existing.ID);
|
||||||
ModelStore.PurgeDeletable(s => s.ID == existing.ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PreImport(item);
|
PreImport(item);
|
||||||
@ -361,12 +369,12 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Log($"Import of {item} successfully completed!", LoggingTarget.Database);
|
LogForModel(item, "Import successfully completed!");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
if (!(e is TaskCanceledException))
|
if (!(e is TaskCanceledException))
|
||||||
Logger.Error(e, $"Import of {item} failed and has been rolled back.", LoggingTarget.Database);
|
LogForModel(item, "Database import or population failed and has been rolled back.", e);
|
||||||
|
|
||||||
rollback();
|
rollback();
|
||||||
flushEvents(false);
|
flushEvents(false);
|
||||||
|
Reference in New Issue
Block a user