migrate to getLineageIterator to save memory

This commit is contained in:
Doug Bell 2010-06-01 16:22:42 -05:00
parent cc87552a22
commit 2c75ab27e6
34 changed files with 794 additions and 187 deletions

View file

@ -184,8 +184,15 @@ sub www_assetTree {
$session->http->setCacheControl("none");
my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session);
my @crumb;
my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1});
foreach my $ancestor (@{$ancestors}) {
my $ancestorIter = $base->getLineageIterator(["self","ancestors"]);
while ( 1 ) {
my $ancestor;
eval { $ancestor = $ancestorIter->() };
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
$session->log->error($x->full_message);
next;
}
last unless $ancestor;
my $url = $ancestor->getUrl("op=formHelper;sub=assetTree;class=Asset;formId=".$session->form->process("formId"));
$url .= ";classLimiter=".$session->form->process("classLimiter","className") if ($session->form->process("classLimiter","className"));
push(@crumb,'<a href="'.$url.'" class="crumb">'.$ancestor->get("menuTitle").'</a>');
@ -224,10 +231,17 @@ sub www_assetTree {
</style></head><body>
<div class="base">
<div class="crumbTrail">'.join(" &gt; ", @crumb)."</div><br />\n";
my $children = $base->getLineage(["children","self"],{returnObjects=>1});
my $childIter = $base->getLineageIterator(["children","self"]);
my $i18n = WebGUI::International->new($session);
my $limit = $session->form->process("classLimiter","className");
foreach my $child (@{$children}) {
while ( 1 ) {
my $child;
eval { $child = $childIter->() };
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
$session->log->error($x->full_message);
next;
}
last unless $child;
next unless $child->canView;
if ($limit eq "" || $child->get("className") =~ /^$limit/) {
my $tempChild = $child->get("title");

View file

@ -208,13 +208,27 @@ JS
my $output = '<div class="nav">';
my $base = WebGUI::Asset->newByUrl($session) || WebGUI::Asset->getRoot($session);
my @crumb;
my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1});
foreach my $ancestor (@{$ancestors}) {
my $ancestorIter = $base->getLineageIterator(["self","ancestors"]);
while ( 1 ) {
my $ancestor;
eval { $ancestor = $ancestorIter->() };
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
$session->log->error($x->full_message);
next;
}
last unless $ancestor;
push(@crumb,'<a href="'.$ancestor->getUrl("op=formHelper;class=HTMLArea;sub=pageTree").'" class="crumb">'.$ancestor->get("menuTitle").'</a>');
}
$output .= '<div class="crumbTrail">'.join(" &gt; ", @crumb)."</div>\n<ul>";
my $children = $base->getLineage(["children"],{returnObjects=>1});
foreach my $child (@{$children}) {
my $childIter = $base->getLineageIterator(["children"]);
while ( 1 ) {
my $child;
eval { $child = $childIter->() };
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
$session->log->error($x->full_message);
next;
}
last unless $child;
next unless $child->canView;
$output .= '<li><a href="#" class="selectLink" onclick="selectLink(\'' . $child->get('url') . '\'); return false;">['
. $i18n->get("select") . ']</a> <a href="' . $child->getUrl("op=formHelper;class=HTMLArea;sub=pageTree")
@ -253,8 +267,15 @@ JS
my @crumb;
my $media;
my $ancestors = $base->getLineage(["self","ancestors"],{returnObjects=>1});
foreach my $ancestor (@{$ancestors}) {
my $ancestorIter = $base->getLineageIterator(["self","ancestors"]);
while ( 1 ) {
my $ancestor;
eval { $ancestor = $ancestorIter->() };
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
$session->log->error($x->full_message);
next;
}
last unless $ancestor;
push(@crumb,'<a href="'.$ancestor->getUrl("op=formHelper;class=HTMLArea;sub=imageTree").'" class="crumb">'.$ancestor->get("menuTitle").'</a>');
if ($ancestor->get('assetId') eq 'PBasset000000000000003') {
$media = $ancestor;
@ -276,8 +297,8 @@ JS
$output .= '<div class="crumbTrail">'.join(" &gt; ", @crumb)."</div>\n<ul>";
my $useAssetUrls = $session->config->get("richEditorsUseAssetUrls");
my $children = $base->getLineage(["children"],{returnObjects=>1});
foreach my $child (@{$children}) {
my $children = $base->getLineage(["children"]);
while ( my $child = $children->() ) {
next unless $child->canView;
$output .= '<li>';
if ($child->isa('WebGUI::Asset::File::Image')) {

View file

@ -125,8 +125,18 @@ the available Rich Text Editor assets.
sub getOptions {
my $self = shift;
my $editors = WebGUI::Asset->getRoot($self->session)->getLineage(['descendants'], {includeOnlyClasses => ['WebGUI::Asset::RichEdit'], returnObjects => 1});
my %options = map { $_->getId => $_->getTitle } @$editors;
my $editorIter = WebGUI::Asset->getRoot($self->session)->getLineageIterator( ['descendants'], {includeOnlyClasses => ['WebGUI::Asset::RichEdit']});
my %options;
while ( 1 ) {
my $editor;
eval { $editor = $editorIter->() };
if ( my $x = WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
$session->log->error($x->full_message);
next;
}
last unless $editor;
$options{ $editor->getId } = $editor->getTitle;
}
return \%options;
}