Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ======================== DBIx::Custom ===============================
- my $result = $self->dbh->select( ['sap_exists','order_exists','sale_exists','sales_more'],
- table => 'sc_sap_import',
- append => 'order by id desc limit 0, 1'
- );
- $funnel_data = $result->one;
- my $result = $self->dbh->select( ['DATE_FORMAT(date, \'%d.%m.%Y\') as dates','visits'],
- table => 'sc_metrika_import',
- append => 'ORDER BY date DESC ' . $limit
- )->all;
- my $result = $self->dbh->execute("SELECT a.id, a.date_add, a.date_event, a.comment, b.title as status_name,
- c.title as event_name, d.title as client_name
- FROM sc_history a INNER JOIN sc_status b ON a.status = b.id
- INNER JOIN sc_event_type c ON a.event_type = c.id
- INNER JOIN sc_clients d ON a.client_id = d.id
- WHERE a.user_id = :user_id AND d.is_delete = :not_delete ORDER BY a.date_event DESC
- LIMIT :start_page, :per_page ",
- {'user_id' => $user->{id}, 'not_delete' => 'N', 'start_page' => $per_page*$page_id, 'per_page' => $per_page });
- return $result->all;
- == Update ==
- $self->dbh->update( {
- title => $params->{title},
- title2 => $params->{title2},
- },
- table => 'sc_event_type',
- where => {id => $params->{id}}
- )
- == delete ==
- my $result = $self->dbh->select(qw[id], table => 'sc_history', where => {event_type => $id });
- =========================== DBIx::Struct =================================
- my $result = all_rows([
- "mc_news a" =>
- -join => 'mc_users b',
- -join => "mc_categories c",
- -columns => ['a.*', 'b.fullname as author_name', 'b.profile_foto', 'c.title as category_name' ]
- ],
- -where => { 'a.date_pub' => {'<=', \"now()" }, 'a.publish' => 1 },
- # automaticly join - based on forein keys
- # -on => "mc_news.author = mc_users.id",
- -order_by => "a.id DESC",
- -limit => $per_page,
- -offset => $offset*$per_page,
- sub { +{ delay => $delay += 90, %{$_->data} } }
- );
- ====
- for_rows( [ mc_news => -distinct => ['main_foto_url'] ],
- -limit => $self->conf->{per_page},
- -offset => $offset*$self->conf->{per_page},
- # проверка на undef и наличие файла в FS
- sub { push( @images, $_->TO_JSON ) if ( defined $_->main_foto_url and -f $prefix . $_->main_foto_url ); ); 1 } );
- == Update ==
- my $row = one_row( "mc_news", { id => $params->{id} } );
- $row->$_($params->{$_}) for (keys %$params) ;
- $row->update;
- == delete ==
- my $row = one_row( 'mc_news', { id => $id } );
- $row->delete();
- ====
- ============================ Benchmarks ============================
- __DATA__
- Benchmark: running Custom, DBI, Struct for at least 10 CPU seconds...
- Custom: 12 wallclock secs ( 9.73 usr + 0.86 sys = 10.59 CPU) @ 833.87/s (n=8834)
- DBI: 12 wallclock secs ( 7.34 usr + 2.66 sys = 10.00 CPU) @ 8505.95/s (n=85068)
- Struct: 10 wallclock secs ( 9.08 usr + 0.94 sys = 10.02 CPU) @ 2435.05/s (n=24387)
- Rate Custom Struct DBI
- Custom 834/s -- -66% -90%
- Struct 2435/s 192% -- -71%
- DBI 8506/s 920% 249% --
- Benchmark: running Custom, DBI, Struct for at least 10 CPU seconds...
- Custom: 10 wallclock secs ( 9.23 usr + 0.83 sys = 10.06 CPU) @ 844.96/s (n=8502)
- DBI: 12 wallclock secs ( 7.50 usr + 2.70 sys = 10.20 CPU) @ 8794.96/s (n=89735)
- Struct: 11 wallclock secs ( 9.36 usr + 1.27 sys = 10.62 CPU) @ 2489.36/s (n=26447)
- Rate Custom Struct DBI
- Custom 845/s -- -66% -90%
- Struct 2489/s 195% -- -72%
- DBI 8795/s 941% 253% --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement