Skip to content
Permalink
Browse files

Speed up deletion of files in batches

  • Loading branch information...
da3dsoul committed Jul 6, 2019
1 parent 3435929 commit d391430f58dacf86a6323616dd7196d47ba3dd67
Submodule Shoko.Commons updated 1 files
+1 −1 Shoko.Models
@@ -911,6 +911,29 @@ public string DeleteVideoLocalPlaceAndFile(int videoplaceid)
return ex.Message;
}
}

/// <summary>
/// Deletes the VideoLocal record and the associated physical file
/// </summary>
/// <param name="videoplaceid"></param>
/// <returns></returns>
[HttpDelete("File/Physical/{videoplaceid}/SkipFolder")]
public string DeleteVideoLocalPlaceAndFileSkipFolder(int videoplaceid)
{
try
{
SVR_VideoLocal_Place place = RepoFactory.VideoLocalPlace.GetByID(videoplaceid);
if (place?.VideoLocal == null)
return "Database entry does not exist";

return place.RemoveAndDeleteFile(false).Item2;
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
return ex.Message;
}
}

[HttpPost("File/Resume/{videoLocalID}/{resumeposition}/{userID}")]
public string SetResumePosition(int videoLocalID, long resumeposition, int userID)
@@ -2549,11 +2572,18 @@ public string DeleteAnimeSeries(int animeSeriesID, bool deleteFiles, bool delete
{
foreach (SVR_VideoLocal vid in ep.GetVideoLocals())
{
foreach (SVR_VideoLocal_Place place in vid.Places)
var places = vid.Places;
for (int index = 0; index < places.Count; index++)
{
SVR_VideoLocal_Place place = places[index];
if (deleteFiles)
{
(bool success, string result) = place.RemoveAndDeleteFile();
bool success;
string result;
if (index < places.Count - 1)
(success, result) = place.RemoveAndDeleteFile(false);
else
(success, result) = place.RemoveAndDeleteFile();
if (!success) return result;
}
else
@@ -419,7 +419,7 @@ public bool RefreshMediaInfo()
return false;
}

public (bool, string) RemoveAndDeleteFile()
public (bool, string) RemoveAndDeleteFile(bool deleteFolder = true)
{
// TODO Make this take an argument to disable removing empty dirs. It's slow, and should only be done if needed
try
@@ -465,15 +465,15 @@ public bool RefreshMediaInfo()
{
if (ex is FileNotFoundException)
{
RecursiveDeleteEmptyDirectories(ImportFolder?.ImportFolderLocation, true);
if (deleteFolder) RecursiveDeleteEmptyDirectories(ImportFolder?.ImportFolderLocation, true);
RemoveRecord();
return (true, string.Empty);
}

logger.Error($"Unable to delete file '{FullServerPath}': {ex}");
return (false, $"Unable to delete file '{FullServerPath}'");
}
RecursiveDeleteEmptyDirectories(ImportFolder?.ImportFolderLocation, true);
if (deleteFolder) RecursiveDeleteEmptyDirectories(ImportFolder?.ImportFolderLocation, true);
RemoveRecord();
// For deletion of files from Trakt, we will rely on the Daily sync
return (true, string.Empty);

0 comments on commit d391430

Please sign in to comment.
You can’t perform that action at this time.