--- lib/Strix.pm 2008/06/17 14:43:39 192 +++ lib/Strix.pm 2008/06/17 21:27:31 193 @@ -32,6 +32,7 @@ =cut our $instance_dbh; +our @instances_active; sub dbh { my $self = shift; @@ -59,6 +60,13 @@ $dbh->{pg_enable_utf8} = 1; $instance_dbh->{$instance} = $dbh; + push @instances_active, $instance; + + if ( $#instances_active > 5 ) { + my $i = shift @instances_active; + warn "## remove connection to instance $instance\n"; + delete( $instance_dbh->{$i} ); + } warn "## instance_dbh = ",dump( $instance_dbh ) if $debug; @@ -175,35 +183,27 @@ } -=head2 sitemap +=head2 sites - my $sitemap = $strix->sitemap( $site_id, $uid ); + my @sites = $strix->sites; =cut -sub sitemap { +sub sites { my $self = shift; - my ( $site_id, $uid ) = @_; - my $sitemap; + my @sites; - my $query = "SELECT *, ( length(ordstr)/3 ) - 1 AS depth FROM site WHERE id = ?"; - $query = "SELECT *, coalesce(( length(ordstr)/3 ) - 1,0) AS depth FROM site ORDER BY ordstr" unless $site_id; - - my $sth = $self->dbh->prepare( $query ); - if ( $site_id ) { - $sth->execute( $site_id ); - } else { - $sth->execute; - } + my $sth = $self->dbh->prepare( + "SELECT *, coalesce(( length(ordstr)/3 ) - 1,0) AS depth FROM site ORDER BY ordstr" + ); + $sth->execute; while (my $row = $sth->fetchrow_hashref() ) { - warn dump( $row ) if $debug; - - $sitemap->{ $row->{naziv} } = $self->site_navigation( $site_id, $uid ); + push @sites, $row; } - return $sitemap; + return @sites; } =head2 site_navigation @@ -232,7 +232,10 @@ while (my $kat = $sth->fetchrow_hashref() ) { warn "# kat = ",dump( $kat ) if $debug; - die "no depth" unless $kat->{depth}; + if ( ! $kat->{depth} ) { + Jifty->log->error("depth increased to 1 in ",dump( $kat )); + $kat->{depth} = 1; + } my $node = { type => 'category' }; foreach my $c ( qw/naziv url/ ) {