/[A3C]/lib/Strix.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Strix.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 212 by dpavlin, Tue Jun 17 21:27:31 2008 UTC revision 213 by dpavlin, Fri Jun 20 20:44:18 2008 UTC
# Line 11  use Data::Dump qw/dump/; Line 11  use Data::Dump qw/dump/;
11  use Carp qw/confess/;  use Carp qw/confess/;
12  use Jifty;  use Jifty;
13    
14    use File::Slurp;
15    use JSON::XS;
16    use Carp qw/confess/;
17    
18  our $debug = 0;  our $debug = 0;
19    
20  =head1 NAME  =head1 NAME
# Line 220  sub site_navigation { Line 224  sub site_navigation {
224          $uid ||= 1; # anonymous          $uid ||= 1; # anonymous
225  #       $uid ||= 2; # admin  #       $uid ||= 2; # admin
226    
227            my $cache_format = 'site-%d-navigation-for-uid-%d.js';
228            if ( my $data = $self->read_cache( $cache_format, $site_id, $uid ) ) {
229                    return $data;
230            }
231    
232    
233          my $sth = $self->dbh->prepare(          my $sth = $self->dbh->prepare(
234          "SELECT kategorija.*, ((length(prikaz)+length(coalesce(ordstr,'')))/3)-1 as depth FROM kategorija JOIN navigacija ON (kategorija.id = kategorija_id), site WHERE site_id = ? AND site.id = site_id AND userCanDoOnObject(?, 1, 'kats', kategorija.id) ORDER BY prikaz");          "SELECT kategorija.*, ((length(prikaz)+length(coalesce(ordstr,'')))/3)-1 as depth FROM kategorija JOIN navigacija ON (kategorija.id = kategorija_id), site WHERE site_id = ? AND site.id = site_id AND userCanDoOnObject(?, 1, 'kats', kategorija.id) ORDER BY prikaz");
235          $sth->execute( $site_id, $uid );          $sth->execute( $site_id, $uid );
# Line 304  sub site_navigation { Line 314  sub site_navigation {
314    
315          }          }
316    
317            $self->write_cache( $navigation, $cache_format, $site_id, $uid );
318    
319          return $navigation;          return $navigation;
320    
321  }  }
322    
323    =head2 cache_path
324    
325      my $path = $strix->cache_path( 'format-%d', $var, ... );
326    
327    =cut
328    
329    sub cache_path {
330            my $self = shift;
331    
332            warn "# cache_path",dump( @_ );
333    
334            my $path = Jifty::Util->absolute_path( 'var/strix' );
335    
336            if ( ! -e $path ) {
337                    mkdir $path || die "can't create $path: $!";
338            }
339    
340            $path .= '/' . sprintf( shift, @_ );    # XXX shift is important here!
341            return $path;
342    }
343    
344    =head2 write_cache
345    
346      write_cache( $data, 'format-%d', $var, ... );
347    
348    =cut
349    
350    sub write_cache {
351            my $self = shift;
352            my $data = shift || confess "no data?";
353            my $path = $self->cache_path( @_ );
354            write_file( $path, encode_json( $data )) || die "can't save into $path: $!";
355    }
356    
357    =head2 read_cache
358    
359            my $data = read_cache( 'format-%d', $var ... );
360    
361    =cut
362    
363    sub read_cache {
364            my $self = shift;
365            my $path = $self->cache_path( @_ );
366            return unless -e $path;
367            warn "# read_cache( $path )";
368            return decode_json( read_file( $path ) ) || die "can't read $path: $!";
369    }
370    
371  1;  1;

Legend:
Removed from v.212  
changed lines
  Added in v.213

  ViewVC Help
Powered by ViewVC 1.1.26