Author Topic: Deleting a package with a large model  (Read 3524 times)

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1374
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Deleting a package with a large model
« on: March 03, 2022, 12:04:02 am »
Hi,

I have a large EA project which needs to be cleaned of a number of package branches as part of a publication process. The production EA project is duplicated to a local publication EA project file. A script has been defined to delete specific package branches.
This used to take a few minutes until a large package branch was introduced, with ~5000 classes, 100000 attributes, 30000 operations, and 20000 connectors.
Deleting this package on a local EAPx file took ages and generated a DB error.
So I moved to a feap file and I managed to manually delete the package, yet it took around 10 minutes.

I ran the same test with a script executing pkg.Packages.DeleteAt() method but it eventually stops according to the log messages (somehow restarting EA shows that the package branch has been deleted).
Is there a way to run a faster bulk delete ? The only option I can think of is to use DELETE queries, yet they can be complicated to define and I'm not sure to reach exhaustivity.

Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Deleting a package with a large model
« Reply #1 on: March 03, 2022, 12:28:48 am »
I (sortof) solved that issue by creating a script that does a bottom up delete: starting at the lowest level of packages and then going up.
This script usually (not always, I'm not sure why) works for us without causing problems.

If you have a single package with a lot of elements, I would suggest to move elements in batches to a temporary package, and then deleting that temporary package.
That will allow EA to do the heavy lifting and cleaning up what needs to be cleaned up.

Code: [Select]
'[path=\Projects\Project A\Model Management]
'[group=Model Management]
option explicit

!INC Local Scripts.EAConstants-VBScript

'
' Script Name: Delete Package Tree (bottom up)
' Author: Geert Bellekens
' Purpose: Delete a whole package tree bottom up
' Date: 2019-04-03
'
const outPutName = "Delete package tree"

sub main
'create output tab
Repository.CreateOutputTab outPutName
Repository.ClearOutput outPutName
Repository.EnsureOutputVisible outPutName
'get selected package
dim selectedPackage as EA.Package
set selectedPackage = Repository.GetTreeSelectedPackage
if not selectedPackage is nothing then
'ask for confirmation
dim userIsSure
userIsSure = Msgbox("Are you sure you want to delete the package '" &selectedPackage.Name & "' and all its subPackages? '", vbYesNo+vbExclamation, "Delete Package " &selectedPackage.Name & "?")
if userIsSure = vbYes then
Repository.WriteOutput outPutName, now() & " Starting delete package tree for package '"& selectedPackage.Name &"'", 0
'delete the package using it's parent
deletePackageTree selectedPackage, nothing
'refresh
Repository.RefreshModelView 0
'let user know
Repository.WriteOutput outPutName, now() & " Finished delete package tree for package '"& selectedPackage.Name &"'", 0
end if
end if
end sub

function deletePackageTree(package, parentPackage)
'first delete subPackages
dim subPackage as EA.Package
for each subPackage in package.Packages
deletePackageTree subPackage, package
next
'then delete owned elements
dim j
for j = package.Elements.Count -1 to 0 step -1
package.Elements.DeleteAt j , false
next
'then get parent package if needed
if parentPackage is nothing _
  and package.ParentID > 0 then
set parentPackage = Repository.GetPackageByID(package.ParentID)
end if
'stop if parentPackage still not found
if parentPackage is nothing then
exit function
end if
'then delete this package using it's parent package
dim i
i = 0
dim tempPackage as EA.Package
for each tempPackage in parentPackage.Packages
if tempPackage.PackageID = package.PackageID then
Repository.WriteOutput outPutName, now() & " Deleting package '"& package.Name &"'", 0
parentPackage.Packages.DeleteAt i, false
parentPackage.Packages.Refresh
exit for
end if
'up counter
i = i + 1
next
end function

main

Geert

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1374
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: Deleting a package with a large model
« Reply #2 on: March 07, 2022, 09:57:27 pm »
Hi Geert,

Thank you for your help.
I tried your script which resulted still in a lengthly deletion. Your suggestion to move all elements to a temp package seems however to provide much better results  :)
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Deleting a package with a large model
« Reply #3 on: March 07, 2022, 10:13:14 pm »
Hi Geert,

Thank you for your help.
I tried your script which resulted still in a lengthly deletion. Your suggestion to move all elements to a temp package seems however to provide much better results  :)
Cool, thanks for the feedback. I'll remember that if I ever have a similar issue.

Geert