Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[25.x] Delete TenantMediaSet in Batch and safeguard loading detached media #1992

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ codeunit 1927 "Media Cleanup"

/// <summary>
/// Deletes all detached tenant media sets.
/// Note: This function will delete detached media set in batches of 10 and commit in between each batch.
/// This is to ensure we don't get stuck always trying to delete the same media and time out.
/// </summary>
procedure DeleteDetachedTenantMediaSet()
begin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ codeunit 1928 "Media Cleanup Impl."
repeat
if TenantMedia.Get(TenantMediaSet."Media ID".MediaId()) then begin
TempTenantMediaVar := TenantMedia;
TempTenantMediaVar.Insert();
MediaLoaded += 1;
if TempTenantMediaVar.Insert() then
MediaLoaded += 1;
if MediaLoaded >= RecordLimit then
exit(false);
end;
Expand Down Expand Up @@ -162,16 +162,19 @@ codeunit 1928 "Media Cleanup Impl."
var
[SecurityFiltering(SecurityFilter::Ignored)]
TenantMediaSet: Record "Tenant Media Set";
SplitList: List of [List of [Guid]];
MediaSetOrphans: List of [Guid];
Orphan: Guid;
MediaOrphanSubList: List of [Guid];
begin
if not TenantMediaSet.WritePermission() then
exit;

MediaSetOrphans := MediaSet.FindOrphans();
foreach Orphan in MediaSetOrphans do begin
TenantMediaSet.SetRange(ID, Orphan);
SplitListIntoSubLists(MediaSetOrphans, 10, SplitList);
foreach MediaOrphanSubList in SplitList do begin
TenantMediaSet.SetFilter(ID, CreateOrFilter(MediaOrphanSubList));
TenantMediaSet.DeleteAll();
Commit(); // Ensure we keep the progress even on timeout (in case of large amounts of detached media).
end;
end;

Expand Down
Loading