<-- Back

Direct deletion of System.FileDocument records from the database is not supported in Mendix Cloud

Issue

Deleting a large volume of System.FileDocument records through a microflow is slow, and the deletion rate does not keep up with the rate at which new files are created. Deleting the records with Structured Query Language (SQL) directly in the database, and the files directly in file storage, is not a supported alternative.

Environment

Applications hosted in Mendix Cloud

Cause

The System.FileDocument entity stores only the metadata of a file. The file content is kept in the configured file storage, and the Mendix Runtime maintains the link between the database record and the stored file. When an object is deleted through the Mendix Runtime, the Runtime removes the database record and, according to the com.mendix.storage.PerformDeleteFromStorage setting, the stored file.

Changes made outside the Mendix Runtime bypass this logic. Deleting records with SQL leaves the stored files without a database record (orphaned files), and deleting files from storage leaves database records that point to missing files. The Mendix Runtime does not detect such changes, and other tables or entities can still reference the deleted records. Direct changes to the database or file storage are therefore not supported.

The long duration of a microflow deletion is caused by the additional work performed for each object, such as event handlers, cascading deletes, and association lookups, not by the deletion of the record itself.

Solution / Workaround

Direct deletion of System.FileDocument records from the database or of files from file storage is not supported. Delete the records through the Mendix Runtime and reduce the time spent per object. The following steps describe the approach:

  1. Check for event handlers on System.FileDocument and its specializations. Before-delete and after-delete event handlers run for every deleted object and can dominate the deletion time.

  2. Check the delete behavior of the associations that reference the entity. Cascading deletes and unindexed associations increase the time per object. Add indexes to the associations that are used during deletion.

  3. Retrieve the objects in batches with a fixed limit, delete the batch with a single Delete activity, and end the transaction before the next batch. Compare the time per object, not the time per batch, when testing different batch sizes.

  4. Run the deletion in parallel, for example with the Task Queue. Assign each task a separate set of objects, for example a range of creation dates, and monitor the database load.

  5. Add a retention step to the flows that create the files, for example, a scheduled event that deletes files older than a defined age. This stops the growth of the backlog.

  6. Verify the com.mendix.storage.PerformDeleteFromStorage custom runtime setting. The value AllFiles removes the stored file when the record is deleted. The values TemporaryFiles and NoFiles keep the stored file.

If the volume remains too large after these changes, create a Mendix Support ticket with the number of records, the entity names and the measured deletion time per batch.

Internal information related

293839

Additional information

Mendix documentation:

Have more questions? Submit a request

0 Comments

Article is closed for comments.

To provide feedback, please open a ticket here. Don't forget to include the article's URL along with the feedback you would like to provide.