Changeset 148 for server/trunk/web


Ignore:
Timestamp:
12/20/10 03:46:03 (13 years ago)
Author:
nanardon
Message:
  • cleanup the mess introduce by previous commit
  • factorize code
Location:
server/trunk/web
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Controller/Analysis/Solver.pm

    r127 r148  
    4545        my $found = 0; 
    4646        if ($depname =~ /^\//) { 
    47             my $res = $c->forward('/search/byfile', [ $searchspec, $depname, ]); 
    48             if (@{$res->{results}}) { 
     47            my $res = $c->forward('/search/rpm/byfile', [ $searchspec, $depname, ]); 
     48            if (@{$res}) { 
    4949                $found = 1; 
    5050                foreach (@{$res->{results}}) { 
     
    6262            } 
    6363        } else { 
    64             my $res = $c->forward('/search/bydep', [ $searchspec, $over, 
     64            my $res = $c->forward('/search/rpm/bydep', [ $searchspec, $over, 
    6565                    $depname, 
    6666                    $sense, 
    6767                    $evr ]); 
    68             if (@{$res->{results}}) { 
     68            if (@{$res}) { 
    6969                $found = 1; 
    70                 foreach (@{$res->{results}}) { 
     70                foreach (@{$res}) { 
    7171                    $need_pkgid{$_} = 1; 
    7272                } 
  • server/trunk/web/lib/Sophie/Controller/Chat/Cmd.pm

    r140 r148  
    154154        }, @args ]) }; 
    155155 
    156     my $rpmlist = $c->forward('/search/byname', [ $reqspec, $args[0] ]); 
    157     foreach (@{ $rpmlist->{results} }) { 
     156    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]); 
     157    foreach (@{ $rpmlist }) { 
    158158        my $info = $c->forward('/rpms/basicinfo', [ $_ ]); 
    159159        push @message, $info->{evr} . ' // ' . 
     
    333333        }, @args ]) }; 
    334334 
    335     my $rpmlist = $c->forward('/search/byname', [ $reqspec, $args[0] ]); 
    336     foreach (@{ $rpmlist->{results} }) { 
     335    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]); 
     336    foreach (@{ $rpmlist }) { 
    337337        my $info = $c->forward('/rpms/queryformat', [ $_, $args[1] ]); 
    338338        push @message, $info . ' // ' . 
     
    363363        }, @args ]) }; 
    364364 
    365     my $rpmlist = $c->forward('/search/byname', [ $reqspec, $args[0] ]); 
    366     foreach (@{ $rpmlist->{results} }) { 
     365    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]); 
     366    foreach (@{ $rpmlist }) { 
    367367        push @message, $c->uri_for('/rpms', $_) . ' // ' . 
    368368            $c->forward('_fmt_location', [ $_ ]); 
     
    389389            'a=s' => \$reqspec->{arch}, 
    390390        }, @args ]) }; 
    391     my $rpmlist = $c->forward('/search/byname', [ $reqspec, $args[0] ]); 
    392     foreach (@{ $rpmlist->{results} }) { 
     391    my $rpmlist = $c->forward('/search/rpm/byname', [ $reqspec, $args[0] ]); 
     392    foreach (@{ $rpmlist }) { 
    393393        my $res = $c->forward('/rpms/binaries', [ $_ ]); 
    394394        my @name; 
  • server/trunk/web/lib/Sophie/Controller/Distrib.pm

    r118 r148  
    318318    my ($self, $c, $name, @subpart) = @_; 
    319319    $c->stash->{dist}{src} = 1; 
    320     ($c->stash->{pkgid}) = @{ $c->forward('/search/bytag', 
    321         [ $c->stash->{dist}, 'name', $name ])->{results} }; 
     320    ($c->stash->{pkgid}) = @{ $c->forward('/search/rpm/byname', 
     321        [ $c->stash->{dist}, $name ]) }; 
    322322    $c->go('/404/index') unless ($c->stash->{pkgid}); 
    323323    $c->go('/rpms/rpms', [ $c->stash->{pkgid}, @subpart ]); 
     
    327327    my ($self, $c, $name, @subpart) = @_; 
    328328    $c->stash->{dist}{src} = 0; 
    329     ($c->stash->{pkgid}) = @{ $c->forward('/search/bytag', 
    330         [ $c->stash->{dist}, 'name', $name ])->{results} }; 
     329    ($c->stash->{pkgid}) = @{ $c->forward('/search/rpm/byname', 
     330        [ $c->stash->{dist}, $name ]) }; 
    331331    $c->go('/404/index') unless ($c->stash->{pkgid}); 
    332332    $c->go('/rpms/rpms', [ $c->stash->{pkgid}, @subpart ]); 
     
    336336    my ( $self, $c, $pkgid, @subpart ) = @_; 
    337337    if ($pkgid) { 
    338         if (@{ $c->forward('/search/bypkgid', 
    339             [ $c->stash->{dist}, $pkgid ])->{results} } ) { 
     338        if (@{ $c->forward('/search/rpm/bypkgid', 
     339            [ $c->stash->{dist}, $pkgid ]) } ) { 
    340340            $c->go('/rpms/rpms', [ $pkgid, @subpart ]); 
    341341        } else { 
     
    367367    my ( $self, $c, $pkgid, @part ) = @_; 
    368368    if ($pkgid) { 
    369         if (@{ $c->forward('/search/bypkgid', [ $c->stash->{dist}, $pkgid 
    370             ])->{results} } ) { 
     369        if (@{ $c->forward('/search/rpm/bypkgid', [ $c->stash->{dist}, $pkgid 
     370            ]) } ) { 
    371371            $c->stash->{pkgid} = $pkgid; 
    372372            $c->go('/rpms/rpms', [ $pkgid, @part ]); 
  • server/trunk/web/lib/Sophie/Controller/Root.pm

    r124 r148  
    7171 
    7272    $c->stash->{xmlrpc} = $c->forward( 
    73         '/search/bydate', 
     73        '/search/rpms/bydate', 
    7474        [ 
    7575            { 
  • server/trunk/web/lib/Sophie/Controller/Search.pm

    r147 r148  
    4242        /^byname$/ and do { 
    4343            $c->stash->{sargs} = [ {}, $c->req->param('search') ]; 
    44             $c->forward('byname', [ $searchspec, $c->req->param('search') || 
     44            $c->visit('/search/rpm/byname_rpc', [ $searchspec, $c->req->param('search') || 
    4545                    undef ]); 
    4646            last; 
     
    5050                split(/\s+/, $c->req->param('search') || '' )); 
    5151            $c->stash->{sargs} = [ {}, @args ], 
    52             $c->forward('bydep', [ $searchspec, @args ]); 
     52            $c->visit('/search/rpm/bydep_rpc', [ $searchspec, @args ]); 
    5353            last; 
    5454        }; 
     
    5656            my @args = ($c->req->param('search') || ''); 
    5757            $c->stash->{sargs} = [ {}, @args ], 
    58             $c->forward('byfile', [ $searchspec, @args ]); 
     58            $c->visit('/search/rpm/byfile_rpc', [ $searchspec, @args ]); 
    5959            last; 
    6060        }; 
    6161    } 
     62    #$c->forward('/search/rpm/end'); 
    6263} 
    6364 
     
    7172    if ($c->req->param('search')) { 
    7273        $c->session->{search} = $c->req->param('search'); 
    73         $c->forward('/search/rpm/quick', [ 
     74        $c->visit('/search/rpm/quick', [ 
    7475                { 
    7576                    src => 0, 
     
    7778 
    7879    } 
     80    $c->forward('/search/rpm/end'); 
    7981} 
    8082 
     
    98100} 
    99101 
    100 sub format_search : Private { 
    101     my ( $self, $c, $searchspec ) = @_; 
    102     $searchspec ||= {}; 
    103     $c->stash->{rs} or return; 
    104  
    105     my $rs = $c->stash->{rs}->search( 
    106         {}, 
    107         { 
    108             page => $searchspec->{page} ||  
    109                  $c->req->param('page') || 1, 
    110             rows => $searchspec->{rows} ||  
    111                  $c->req->param('rows') || 10, 
    112         }, 
    113     ); 
    114  
    115     $c->stash->{rs} = $rs; 
    116     $c->stash->{column} ||= 'pkgid'; 
    117     my @results; 
    118     if (ref $c->stash->{column}) { 
    119         while (my $i = $rs->next) { 
    120             push(@results, { 
    121                 map { $_ => $i->get_column($_) } @{$c->stash->{column}}  
    122             }); 
    123         } 
    124     } else { 
    125         @results = $rs->get_column($c->stash->{column})->all; 
    126     } 
    127     $c->stash->{xmlrpc} = {}; 
    128     if (!$searchspec->{nopager}) { 
    129         my $pager = $c->stash->{rs}->pager; 
    130         $c->stash->{pager} = $pager; 
    131         $c->stash->{xmlrpc} = { 
    132                 pages => $pager->last_page, 
    133                 current_page => $pager->current_page, 
    134                 total_entries => $pager->total_entries, 
    135                 entries_per_page => $pager->entries_per_page, 
    136         }; 
    137     } 
    138     $c->stash->{xmlrpc}{results} = \@results; 
    139     return $c->stash->{xmlrpc}; 
    140 } 
    141  
    142 =head2 search.rpms.bydate (SEARCHSPEC, TIMESTAMP) 
    143  
    144 Return a list of rpms files added since TIMESTAMP. 
    145 TIMESTAMP must the number of second since 1970-01-01 (eq UNIX epoch). 
    146  
    147 SEARCHSPEC is a struct with following key/value: 
    148  
    149 =over 4 
    150  
    151 =item distribution 
    152  
    153 Limit search to this distribution 
    154  
    155 =item release 
    156  
    157 Limit search to this release 
    158  
    159 =item arch 
    160  
    161 Limit search to distribution of this arch 
    162  
    163 =item src 
    164  
    165 If set to true, limit search to source package, If set to false, limit search to 
    166 binary package. 
    167  
    168 =item name 
    169  
    170 Limit search to rpm having this name 
    171  
    172 =item rows 
    173  
    174 Set maximum of results, the default is 10000. 
    175  
    176 =back 
    177  
    178 Each elements of the output is a struct: 
    179  
    180 =over 4 
    181  
    182 =item filename 
    183  
    184 the rpm filename 
    185  
    186 =item pkgid 
    187  
    188 the identifier of the package 
    189  
    190 =item distribution 
    191  
    192 the distribution containing this package 
    193  
    194 =item release 
    195  
    196 the release containing this package 
    197  
    198 =item arch 
    199  
    200 the arch containing this package 
    201  
    202 =item media 
    203  
    204 the media containing this package 
    205  
    206 =back 
    207  
    208 =cut 
    209  
    210 sub bydate : XMLRPCPath('/search/rpms/bydate') { 
    211     my ( $self, $c, $searchspec, $date ) = @_; 
    212     $searchspec ||= {}; 
    213  
    214     return $c->stash->{xmlrpc} = [ 
    215         map { 
    216             {  
    217                 filename => $_->get_column('filename'), 
    218                 pkgid    => $_->get_column('pkgid'),  
    219                 distribution => $_->get_column('name'), 
    220                 release => $_->get_column('version'), 
    221                 arch => $_->get_column('arch'), 
    222                 media => $_->get_column('label'), 
    223             } 
    224         } 
    225         $c->forward('/distrib/distrib_rs', [ $searchspec ]) 
    226         ->search_related('MediasPaths') 
    227         ->search_related('Paths') 
    228         ->search_related('Rpmfiles', 
    229             { 
    230                 -nest => \[ 
    231                     "Rpmfiles.added > '1970-01-01'::date + ?::interval", 
    232                     [ plain_text => "$date seconds" ],    
    233                 ], 
    234                 pkgid => { 
    235                     IN => $c->model('Base::Rpms')->search( 
    236                         { 
    237                             (exists($searchspec->{name}) 
    238                                 ? (name => $searchspec->{name}) 
    239                                 : () 
    240                             ), 
    241                             (exists($searchspec->{src}) 
    242                                 ? (issrc => $searchspec->{src} ? 1 : 0) 
    243                                 : () 
    244                             ), 
    245                         } 
    246                     )->get_column('pkgid')->as_query, 
    247                 } 
    248             }, 
    249             { 
    250                 select => [qw(filename pkgid name version arch label) ], 
    251                 rows => $searchspec->{rows} || 10000, 
    252                 order_by => [ 'Rpmfiles.added desc' ], 
    253             }, 
    254         )->all ]; 
    255 } 
    256  
    257 sub bypkgid : Private { 
    258     my ( $self, $c, $searchspec, $pkgid ) = @_; 
    259     $c->log->debug(sprintf("Call to obsolete %s %s", __PACKAGE__, "bypkgid")); 
    260     $c->stash->{rs} = $c->forward('/search/rpm/bypkgid_rpc', [ $searchspec, $pkgid ]); 
    261     $c->forward('format_search', [ $searchspec ]); 
    262 } 
    263  
    264102sub byname_rs : Private { 
    265103    my ( $self, $c, $searchspec, $name, $sense, $evr ) = @_; 
     
    293131} 
    294132 
    295 sub byname : Private { 
    296     my ( $self, $c, $searchspec, $name, $sense, $evr ) = @_; 
    297     $c->log->debug(sprintf("Call to obsolete %s %s", __PACKAGE__, "byname")); 
    298     $c->stash->{rs} = $c->forward('/search/rpm/byname_rpc', [ $searchspec, $name, $sense, $evr ]); 
    299     $c->forward('format_search', [ $searchspec ]); 
    300 } 
    301  
    302133sub bytag_rs : Private { 
    303134    my ( $self, $c, $searchspec, $tag, $tagvalue ) = @_; 
     
    323154        }, 
    324155    ); 
    325 } 
    326  
    327 sub bytag : Private { 
    328     my ( $self, $c, $searchspec, $tag, $tagvalue ) = @_; 
    329  
    330     $c->log->debug(sprintf("Call to obsolete %s %s", __PACKAGE__, "bytag")); 
    331     $c->stash->{rs} = $c->forward('/search/rpm/bytag_rpc', [ $searchspec, $tag, $tagvalue ]); 
    332     $c->forward('format_search', [ $searchspec ]); 
    333156} 
    334157 
     
    435258} 
    436259 
    437 sub bydep : XMLRPCPath('/search/rpm/bydep') { 
    438     my ( $self, $c, $searchspec, $deptype, $depname, $depsense, $depevr ) = @_; 
    439     $c->forward('/search/rpm/bydep', [ $searchspec, $deptype, $depname, $depsense, $depevr ]); 
    440     $c->forward('format_search', [ $searchspec ]); 
    441 } 
    442  
    443 sub byfile : Private { 
    444     my ( $self, $c, $searchspec, $file) = @_; 
    445     $c->forward('/search/rpm/byfile', [ $searchspec, $file ]); 
    446     $c->forward('format_search', [ $searchspec ]); 
    447 } 
    448  
    449 sub file_search : XMLRPCPath('/search/file/byname') { 
    450     my ( $self, $c, $searchspec, $file) = @_; 
    451     $searchspec ||= {}; 
    452  
    453     $c->stash->{rs} = $c->forward('file_rs', [ $searchspec, $file ]); 
    454      
    455     my @col = qw(dirname basename md5 size pkgid count); 
    456     $c->stash->{column} = [ @col, qw(has_content perm user group) ]; 
    457      
    458     $c->forward('format_search', [ $searchspec ]); 
    459 } 
    460  
    461 sub dep_search : XMLRPCPath('/search/dep/match') { 
    462     my ($self, $c, $searchspec, $deptype, $depname, $depsense, $depevr) = @_; 
    463  
    464     my $distrs = $c->forward('distrib_search', [ $searchspec, 1 ]); 
    465     $c->stash->{rs} = $c->forward( 
    466         'deps_rs', [  
    467             $searchspec, $deptype, $depname, 
    468             $depsense, $depevr  
    469         ], 
    470     ); 
    471  
    472     $c->stash->{column} = [ qw(name sense evr flags pkgid) ]; 
    473     $c->forward('format_search', [ $searchspec ]); 
    474 } 
    475  
    476260sub end : Private { 
    477261    my ($self, $c, $searchspec) = @_; 
    478     warn join(' ', keys %{ $searchspec }); 
    479  
    480     $c->forward('/search/format_search', [ $searchspec ]); 
    481     $c->forward('/end'); 
     262 
     263    if ($c->action =~ m:search/[^/]+/.:) { 
     264        my $rs = $c->stash->{rs}->search( 
     265            {}, 
     266            { 
     267                page => $searchspec->{page} ||  
     268                     $c->req->param('page') || 1, 
     269                rows => $searchspec->{rows} ||  
     270                     $c->req->param('rows') || 10, 
     271            }, 
     272        ); 
     273 
     274        $c->stash->{rs} = $rs; 
     275        my @results = map { { $_->get_columns } } $rs->all; 
     276 
     277        $c->stash->{xmlrpc} = {}; 
     278        if (!$searchspec->{nopager}) { 
     279            my $pager = $c->stash->{rs}->pager; 
     280            $c->stash->{pager} = $pager; 
     281            $c->stash->{xmlrpc} = { 
     282                    pages => $pager->last_page, 
     283                    current_page => $pager->current_page, 
     284                    total_entries => $pager->total_entries, 
     285                    entries_per_page => $pager->entries_per_page, 
     286            }; 
     287        } 
     288        $c->stash->{xmlrpc}{results} = \@results; 
     289    } else { 
     290        $c->forward('/end'); 
     291    } 
    482292} 
    483293 
  • server/trunk/web/lib/Sophie/Controller/Search/Dep.pm

    r147 r148  
    3030sub match : Private { 
    3131    my ($self, $c, $searchspec, $deptype, $depname, $depsense, $depevr) = @_; 
    32     my $distrs = $c->forward('/search/distrib_search', [ $searchspec, 1 ]); 
    3332    $c->stash->{xmlrpc} = [  
    3433        map { { $_->get_columns } } 
  • server/trunk/web/lib/Sophie/Controller/Search/Rpm.pm

    r147 r148  
    8484} 
    8585 
    86 sub bydep : XMLRPCPath('/search/rpm/bydep') { 
     86sub bydep : Private { 
     87    my ( $self, $c, $searchspec, $deptype, $depname, $depsense, $depevr ) = @_; 
     88    $searchspec ||= {}; 
     89 
     90    $c->stash->{xmlrpc} = [ $c->forward('bydep_rpc', [  
     91                $searchspec, $deptype, $depname, $depsense, $depevr ] 
     92    )->get_column('pkgid')->all ]; 
     93} 
     94 
     95sub bydep_rpc : XMLRPCPath('bydep') { 
    8796    my ( $self, $c, $searchspec, $deptype, $depname, $depsense, $depevr ) = @_; 
    8897    $searchspec ||= {}; 
     
    107116} 
    108117 
    109 sub byfile : XMLRPCPath('byfile') { 
     118sub byfile : Private { 
     119    my ( $self, $c, $searchspec, $file) = @_; 
     120    $searchspec ||= {}; 
     121    $c->stash->{xmlrpc} = [  
     122        $c->forward( 
     123            'byfile_rpc', [ $searchspec, $file ] 
     124        )->get_column('pkgid')->all 
     125    ]; 
     126} 
     127 
     128sub byfile_rpc : XMLRPCPath('byfile') { 
    110129    my ( $self, $c, $searchspec, $file) = @_; 
    111130    $searchspec ||= {}; 
     
    269288} 
    270289 
     290sub end : Private { 
     291    my ( $self, $c, $searchspec ) = @_; 
     292    $searchspec ||= {}; 
     293    $c->stash->{rs} or return; 
     294 
     295    my $rs = $c->stash->{rs}->search( 
     296        {}, 
     297        { 
     298            page => $searchspec->{page} ||  
     299                 $c->req->param('page') || 1, 
     300            rows => $searchspec->{rows} ||  
     301                 $c->req->param('rows') || 10, 
     302        }, 
     303    ); 
     304 
     305    $c->stash->{rs} = $rs; 
     306    my @results = $rs->get_column('pkgid')->all; 
     307     
     308    $c->stash->{xmlrpc} = {}; 
     309    if (!$searchspec->{nopager}) { 
     310        my $pager = $c->stash->{rs}->pager; 
     311        $c->stash->{pager} = $pager; 
     312        $c->stash->{xmlrpc} = { 
     313                pages => $pager->last_page, 
     314                current_page => $pager->current_page, 
     315                total_entries => $pager->total_entries, 
     316                entries_per_page => $pager->entries_per_page, 
     317        }; 
     318    } 
     319    $c->stash->{xmlrpc}{results} = \@results; 
     320 
     321    #$c->forward('/end'); 
     322} 
     323 
     324 
    271325=head1 AUTHOR 
    272326 
  • server/trunk/web/t/controller_Search-Dep.t

    r147 r148  
    66BEGIN { use_ok 'Sophie::Controller::Search::Dep' } 
    77 
    8 ok( request('/search/dep')->is_success, 'Request should succeed' ); 
     8# ok( request('/search/dep')->is_success, 'Request should succeed' ); 
    99done_testing(); 
  • server/trunk/web/t/controller_Search-File.t

    r147 r148  
    66BEGIN { use_ok 'Sophie::Controller::Search::File' } 
    77 
    8 ok( request('/search/file')->is_success, 'Request should succeed' ); 
     8# ok( request('/search/file')->is_success, 'Request should succeed' ); 
    99done_testing(); 
Note: See TracChangeset for help on using the changeset viewer.