From ca1cf60d471d4c6695915da263f3d6ade88c9a4c Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 24 Mar 2005 21:53:00 +0000 Subject: [PATCH] fixed an inefficiency in pasting --- docs/changelog/6.x.x.txt | 2 ++ lib/WebGUI/Asset.pm | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 0db98f55b..6b7c44ae0 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -1,5 +1,7 @@ 6.5.5 - Fixed a bug in the collaboration system that caused replies to fail. + - Fixed an inefficency in the asset system that caused a lot of extra work on + the server when pasting. 6.5.4 diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 54f38b9a6..d1ba38388 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -254,20 +254,22 @@ If not present, asset's existing lineage is used. =cut sub cascadeLineage { - my $self = shift; - my $newLineage = shift; - my $oldLineage = shift || $self->get("lineage"); - WebGUI::Cache->new($self->getId)->deleteByRegex(/^asset_/); - WebGUI::Cache->new($self->getId)->deleteByRegex(/^lineage_$oldLineage/); - WebGUI::SQL->write("update asset set - lineage=concat(".quote($newLineage).",substring(lineage from ".(length($oldLineage)+1).")), - lastUpdatedBy=".quote($session{user}{userId}).", - lastUpdated=".time()." - where lineage like ".quote($oldLineage.'%')); + my $self = shift; + my $newLineage = shift; + my $oldLineage = shift || $self->get("lineage"); + my $now = time(); + my $prepared = WebGUI::SQL->prepare("update asset set lineage=?, lastUpdatedBy=".quote($session{user}{userId}).", lastUpdated=$now where assetId=?"); + my $descendants = WebGUI::SQL->read("select assetId,lineage from asset where lineage like ".quote($oldLineage.'%')); + while (my ($assetId, $lineage) = $descendants->array) { + WebGUI::Cache->new("asset_".$assetId)->delete; + WebGUI::Cache->new("lineage_".$lineage)->delete; + my $fixedLineage = $newLineage.substr($lineage,length($oldLineage)); + $prepared->execute([$fixedLineage,$assetId]); + } + $descendants->finish; } - #------------------------------------------------------------------- =head2 checkExportPath ( )