diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index c9284db49..a331d106f 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -5,6 +5,7 @@ - fixed #10526: icalInterval in Calendar.pm - fixed: displaying performance profile data only to an allowed IP address. - fixed #10528: Thingy css error + - fixed: Performance improvements with getting the list of asset packages. 7.7.10 - Made a change to LDAP auth that adds an OR to that query so that it also searches for a row with fieldData REGEXP '^uid=(value-from-ldap-directory-server),'. (Wes Morgan) diff --git a/lib/WebGUI/AssetPackage.pm b/lib/WebGUI/AssetPackage.pm index 0fac4593b..c954de464 100644 --- a/lib/WebGUI/AssetPackage.pm +++ b/lib/WebGUI/AssetPackage.pm @@ -85,33 +85,21 @@ Returns an array of hashes containing title, assetId, and className for all asse =cut sub getPackageList { - my $self = shift; - my $sql = " - select - asset.assetId, - assetData.revisionDate, - asset.className, - assetData.title - from - asset - left join - assetData on asset.assetId=assetData.assetId - where - assetData.isPackage=1 - and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId and - (assetData.status='approved'"; - $sql .= " or assetData.tagId=".$self->session->db->quote($self->session->scratch->get("versionTag")) if ($self->session->scratch->get("versionTag")); - $sql .= ")) and asset.state='published'"; - my $sth = $self->session->db->read($sql); - # MySQL sorts this very slowly, so we do it ourselves + my $self = shift; + my $session = $self->session; + my $db = $session->db; + my @packageIds = $db->buildArray("select distinct assetId from assetData where isPackage=1"); my @assets; - while (my ($id, $date, $class, $title) = $sth->array) { - my $asset = WebGUI::Asset->new($self->session, $id, $class, $date); - push(@assets, [$title, $asset]) if ($asset->get("isPackage")); + ID: foreach my $id (@packageIds) { + my $asset = WebGUI::Asset->newByDynamicClass($session, $id); + next ID unless defined $asset; + next ID unless $asset->canView && $asset->get('isPackage'); + next ID unless ($asset->get('status') eq 'approved' || $asset->get('tagId') eq $session->scratch->get("versionTag")); + push @assets, [$asset->getTitle, $asset]; } - $sth->finish; @assets = map { $_->[1] } sort { $a->[0] cmp $b->[0] } @assets; return \@assets; + } diff --git a/t/Asset/AssetPackage.t b/t/Asset/AssetPackage.t index 9614c216b..fb0e0bc3a 100644 --- a/t/Asset/AssetPackage.t +++ b/t/Asset/AssetPackage.t @@ -23,12 +23,16 @@ use WebGUI::VersionTag; use Test::More; # increment this value for each test you create use Test::MockObject; -plan tests => 6; +plan tests => 10; my $session = WebGUI::Test->session; $session->user({userId => 3}); my $root = WebGUI::Asset->getRoot($session); + +is(scalar @{ $root->getPackageList }, 0, 'WebGUI does not ship with packages'); + my $versionTag = WebGUI::VersionTag->getWorking($session); +WebGUI::Test->tagsToRollback($versionTag); $versionTag->set({name=>"Asset Package test"}); my $folder = $root->addChild({ @@ -71,24 +75,26 @@ is(scalar @{ $targetFolderChildren }, 1, 'target folder now has 1 child'); my $deployedFolder = $targetFolderChildren->[0]; is($deployedFolder->get('title'), 'folder', 'deployed folder has correct title'); +ok(! $deployedFolder->get('isPackage'), 'and is not a package'); my $deployedFolderChildren; $deployedFolderChildren = $deployedFolder->getLineage(["children"], {returnObjects => 1,}); is(scalar @{ $deployedFolderChildren }, 1, 'deployed package folder still has 1 child'); isa_ok($deployedFolderChildren->[0] , 'WebGUI::Asset::Snippet', 'deployed child is a Snippet'); +##Unset isPackage in this versionTag for the next tests +$folder->update({isPackage => 0}); + my $newVersionTag = WebGUI::VersionTag->getWorking($session); +WebGUI::Test->tagsToRollback($newVersionTag); $newVersionTag->commit; +my $newFolder = WebGUI::Asset->new($session, $folder->getId); +ok(! $newFolder->get('isPackage'), 'Disabled isPackage in original folder asset'); +is(scalar @{ $root->getPackageList }, 0, 'getPackageList does not pick up old versions of assets that used to be packages'); + TODO: { local $TODO = "Tests to make later"; ok(0, 'Check package deployment with 2-level package and look for new style templates propagating down the tree'); } -END { - foreach my $tag($versionTag, $newVersionTag) { - if (defined $tag and ref $tag eq 'WebGUI::VersionTag') { - $tag->rollback; - } - } -}