diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 28b7b0a5c..601762a59 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.6.2 + - sped up lineage changes significantly - fixed: site starter fails after site style page - fixed #8829: moveUp.gif, moveDown.gif missing from uploads - fixed #8980: possible to execute arbitrary perl code as any user that can upload files diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 49fb38063..971460652 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -113,16 +113,21 @@ sub cascadeLineage { my $self = shift; my $newLineage = shift; my $oldLineage = shift || $self->get("lineage"); - my $prepared = $self->session->db->prepare("update asset set lineage=? where assetId=?"); - my $descendants = $self->session->db->read("select assetId,lineage from asset where lineage like ?",[$oldLineage.'%']); - my $cache = WebGUI::Cache->new($self->session); - while (my ($assetId, $lineage) = $descendants->array) { - my $fixedLineage = $newLineage.substr($lineage,length($oldLineage)); - $prepared->execute([$fixedLineage,$assetId]); - # we do the purge directly cuz it's a lot faster than instantiating all these assets - $cache->deleteChunk(["asset",$assetId]); - } - $descendants->finish; + my $records = $self->session->db->write( + "UPDATE asset SET lineage=CONCAT(?,SUBSTRING(lineage,?)) WHERE lineage LIKE ?", + [$newLineage, length($oldLineage) + 1, $oldLineage . '%'] + ); + my $cache = WebGUI::Cache->new($self->session); + if ($records > 20) { + $cache->flush; + } + else { + my $descendants = $self->session->db->read("SELECT assetId FROM asset WHERE lineage LIKE ?", [$newLineage]); + while (my ($assetId, $lineage) = $descendants->array) { + $cache->deleteChunk(["asset",$assetId]); + } + $descendants->finish; + } } #-------------------------------------------------------------------