mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:07:38 +08:00
Check filenames and timestamps before reusing an already imported model
This commit is contained in:
parent
73467410ab
commit
c155ab8339
@ -258,9 +258,9 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
/// <returns>The first result for the provided query, or null if no results were found.</returns>
|
||||||
public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().FirstOrDefault(query);
|
public BeatmapSetInfo QueryBeatmapSet(Expression<Func<BeatmapSetInfo, bool>> query) => beatmaps.ConsumableItems.AsNoTracking().FirstOrDefault(query);
|
||||||
|
|
||||||
protected override bool CanUndelete(BeatmapSetInfo existing, BeatmapSetInfo import)
|
protected override bool CanReuseExisting(BeatmapSetInfo existing, BeatmapSetInfo import)
|
||||||
{
|
{
|
||||||
if (!base.CanUndelete(existing, import))
|
if (!base.CanReuseExisting(existing, import))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var existingIds = existing.Beatmaps.Select(b => b.OnlineBeatmapID).OrderBy(i => i);
|
var existingIds = existing.Beatmaps.Select(b => b.OnlineBeatmapID).OrderBy(i => i);
|
||||||
|
@ -332,7 +332,7 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
{
|
{
|
||||||
if (CanUndelete(existing, item))
|
if (CanReuseExisting(existing, item))
|
||||||
{
|
{
|
||||||
Undelete(existing);
|
Undelete(existing);
|
||||||
LogForModel(item, $"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) – skipping import.");
|
LogForModel(item, $"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) – skipping import.");
|
||||||
@ -660,13 +660,29 @@ namespace osu.Game.Database
|
|||||||
protected TModel CheckForExisting(TModel model) => model.Hash == null ? null : ModelStore.ConsumableItems.FirstOrDefault(b => b.Hash == model.Hash);
|
protected TModel CheckForExisting(TModel model) => model.Hash == null ? null : ModelStore.ConsumableItems.FirstOrDefault(b => b.Hash == model.Hash);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// After an existing <typeparamref name="TModel"/> is found during an import process, the default behaviour is to restore the existing
|
/// After an existing <typeparamref name="TModel"/> is found during an import process, the default behaviour is to use/restore the existing
|
||||||
/// item and skip the import. This method allows changing that behaviour.
|
/// item and skip the import. This method allows changing that behaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="existing">The existing model.</param>
|
/// <param name="existing">The existing model.</param>
|
||||||
/// <param name="import">The newly imported model.</param>
|
/// <param name="import">The newly imported model.</param>
|
||||||
/// <returns>Whether the existing model should be restored and used. Returning false will delete the existing and force a re-import.</returns>
|
/// <returns>Whether the existing model should be restored and used. Returning false will delete the existing and force a re-import.</returns>
|
||||||
protected virtual bool CanUndelete(TModel existing, TModel import) => true;
|
protected virtual bool CanReuseExisting(TModel existing, TModel import) =>
|
||||||
|
getFilenames(existing.Files).SequenceEqual(getFilenames(import.Files)) &&
|
||||||
|
// poor-man's (cheap) equality comparison, avoiding hashing unnecessarily.
|
||||||
|
// can switch to full hash checks on a per-case basis (or for all) if we decide this is not a performance issue.
|
||||||
|
getTimestamps(existing.Files).SequenceEqual(getTimestamps(import.Files));
|
||||||
|
|
||||||
|
private IEnumerable<string> getFilenames(List<TFileModel> files)
|
||||||
|
{
|
||||||
|
foreach (var f in files.OrderBy(f => f.Filename))
|
||||||
|
yield return f.Filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<long> getTimestamps(List<TFileModel> files)
|
||||||
|
{
|
||||||
|
foreach (var f in files.OrderBy(f => f.Filename))
|
||||||
|
yield return File.GetLastWriteTimeUtc(Files.Storage.GetFullPath(f.FileInfo.StoragePath)).ToFileTime();
|
||||||
|
}
|
||||||
|
|
||||||
private DbSet<TModel> queryModel() => ContextFactory.Get().Set<TModel>();
|
private DbSet<TModel> queryModel() => ContextFactory.Get().Set<TModel>();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user