← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 17:10:45 2013
Reported on Tue Oct 15 17:12:06 2013

Filename/usr/share/koha/lib/C4/SocialData.pm
StatementsExecuted 13 statements in 807µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11124µs146µsC4::SocialData::::BEGIN@18C4::SocialData::BEGIN@18
11117µs41µsC4::SocialData::::BEGIN@21C4::SocialData::BEGIN@21
11115µs485µsC4::SocialData::::BEGIN@22C4::SocialData::BEGIN@22
11114µs17µsC4::SocialData::::BEGIN@20C4::SocialData::BEGIN@20
0000s0sC4::SocialData::::get_dataC4::SocialData::get_data
0000s0sC4::SocialData::::get_reportC4::SocialData::get_report
0000s0sC4::SocialData::::update_dataC4::SocialData::update_data
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package C4::SocialData;
2
3# This file is part of Koha.
4#
5# Koha is free software; you can redistribute it and/or modify it under the
6# terms of the GNU General Public License as published by the Free Software
7# Foundation; either version 2 of the License, or (at your option) any later
8# version.
9#
10# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16# Suite 330, Boston, MA 02111-1307 USA
17
18342µs2268µs
# spent 146µs (24+122) within C4::SocialData::BEGIN@18 which was called: # once (24µs+122µs) by main::BEGIN@53 at line 18
use Modern::Perl;
# spent 146µs making 1 call to C4::SocialData::BEGIN@18 # spent 122µs making 1 call to Modern::Perl::import
19
20329µs220µs
# spent 17µs (14+3) within C4::SocialData::BEGIN@20 which was called: # once (14µs+3µs) by main::BEGIN@53 at line 20
use C4::Context;
# spent 17µs making 1 call to C4::SocialData::BEGIN@20 # spent 3µs making 1 call to C4::Context::import
21337µs266µs
# spent 41µs (17+25) within C4::SocialData::BEGIN@21 which was called: # once (17µs+25µs) by main::BEGIN@53 at line 21
use Business::ISBN;
# spent 41µs making 1 call to C4::SocialData::BEGIN@21 # spent 24µs making 1 call to Exporter::import
223685µs2955µs
# spent 485µs (15+470) within C4::SocialData::BEGIN@22 which was called: # once (15µs+470µs) by main::BEGIN@53 at line 22
use C4::Koha;
# spent 485µs making 1 call to C4::SocialData::BEGIN@22 # spent 470µs making 1 call to Exporter::import
23
24=head1 NAME
25
- -
59sub get_data {
60 my ( $isbn ) = @_;
61 my $dbh = C4::Context->dbh;
62 my $sth = $dbh->prepare( qq{SELECT * FROM social_data WHERE isbn = ? LIMIT 1} );
63 $sth->execute( $isbn );
64 my $results = $sth->fetchrow_hashref;
65
66 return $results;
67}
68
69=head2 update_data
70
- -
81sub update_data {
82 my ( $output_filepath ) = @_;
83
84 my $dbh = C4::Context->dbh;
85 my $sth = $dbh->prepare( qq{INSERT INTO social_data (
86 `isbn`, `num_critics`, `num_critics_pro`, `num_quotations`, `num_videos`, `score_avg`, `num_scores`
87 ) VALUES ( ?, ?, ?, ?, ?, ?, ? )
88 ON DUPLICATE KEY UPDATE `num_critics`=?, `num_critics_pro`=?, `num_quotations`=?, `num_videos`=?, `score_avg`=?, `num_scores`=?
89 } );
90
91 open my $file, '<', $output_filepath or die "File $output_filepath can not be read";
92 my $sep = qq{;};
93 my $i = 0;
94 my $unknown = 0;
95 while ( my $line = <$file> ) {
96 my ( $isbn, $active, $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores ) = split $sep, $line;
97 next if not $active;
98 eval {
99 $sth->execute( $isbn, $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores,
100 $num_critics, $num_critics_pro, $num_quotations, $num_videos, $score_avg, $num_scores
101 );
102 };
103 if ( $@ ) {
104 warn "Can't insert $isbn ($@)";
105 } else {
106 $i++;
107 }
108 }
109 say "$i data insered or updated";
110}
111
112=head2 get_report
113
- -
118sub get_report {
119 my $dbh = C4::Context->dbh;
120
121 my $sth = $dbh->prepare( qq{
122 SELECT biblionumber, isbn FROM biblioitems
123 } );
124 $sth->execute;
125 my %results;
126 while ( my ( $biblionumber, $isbn ) = $sth->fetchrow() ) {
127 push @{ $results{no_isbn} }, { biblionumber => $biblionumber } and next if not $isbn;
128 my $original_isbn = $isbn;
129 $isbn =~ s/^\s*(\S*)\s*$/$1/;
130 $isbn = GetNormalizedISBN( $isbn, undef, undef );
131 $isbn = Business::ISBN->new( $isbn );
132 next if not $isbn;
133 eval{
134 $isbn = $isbn->as_isbn13->as_string;
135 };
136 next if $@;
137 $isbn =~ s/-//g;
138 my $social_datas = C4::SocialData::get_data( $isbn );
139 if ( $social_datas ) {
140 push @{ $results{with} }, { biblionumber => $biblionumber, isbn => $isbn, original => $original_isbn };
141 } else {
142 push @{ $results{without} }, { biblionumber => $biblionumber, isbn => $isbn, original => $original_isbn };
143 }
144 }
145 return \%results;
146}
147
148113µs1;