To address the significant growth in your namespace caused by Ens.AppData related to the usage of EnsLib.SQL.Snapshot in Business Process Language (BPL):
-
Issue with cleaning EnsLib.SQL.Snapshot:
The snapshot data is not automatically cleaned during purge operations if it is used as a property within response messages. This results in the global ^Ens.AppData growing indefinitely. You can clean this manually in two steps:- Stop the production.
- Run
do ##class(Ens.Adapter).ClearStaticAppData("EnsLib.SQL.Snapshot")in the terminal of the relevant namespace to clearEnsLib.SQL.Snapshotdata from ^Ens.AppData. - Execute SQL command
TRUNCATE TABLE EnsLib_SQL.Snapshotto clean upEnsLib.SQL.Snapshotentries from the database1.
-
Defining %OnDelete Method:
Implementing the%OnDeletemethod in the class holding theEnsLib.SQL.Snapshotproperty ensures proper cleanup of snapshot data during message deletion. Here is an example:Class ResponseMessage Extends Ens.Response { Property SnapshotProp As EnsLib.SQL.Snapshot; ClassMethod %OnDelete(oid As %ObjectIdentity) As %Status [ Private, ServerOnly = 1 ] { set tSC = $$$OK set id = $$$oidPrimary(oid) set obj = ..%OpenId(id) if (obj.SnapshotProp '= "") { set tSC = ##class(EnsLib.SQL.Snapshot).%DeleteId(obj.SnapshotProp.%Id()) } return tSC } }This ensures that associated snapshot data is deleted alongside its parent message1.
-
Alternative Approaches:
- Avoid using
EnsLib.SQL.Snapshotas a direct property. Instead, map the data to another object type (e.g., JSON string or custom class objects). This preventsEnsLib.SQL.Snapshotfrom being stuck in the global ^Ens.AppData1. - Periodically review and manage orphaned data or snapshots using implemented cleanup tasks in your production environment, ensuring your database remains manageable2.
- Avoid using
By implementing these methods, you can reduce the growth in your namespace and ensure that the cleanup of EnsLib.SQL.Snapshot aligns with your application’s lifecycle. 12
Sources:
- Log in to post comments