|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use v5.10.0; |
| 4 |
use Modern::Perl; |
| 5 |
#use Koha::BusinessLogic::Branch2; |
| 6 |
#use Koha::BusinessLogic::Branchrelation; |
| 7 |
use Koha::BusinessLogic::Borrower; |
| 8 |
|
| 9 |
# how many SQL queries did mysql recieved before this script is executed |
| 10 |
my (undef, $before) = split ' ',`mysql -e "show status"|grep Queries`; |
| 11 |
|
| 12 |
my$borrowernumber='7695'; |
| 13 |
|
| 14 |
# retrieve a patron |
| 15 |
my $borrower=Koha::BusinessLogic::Borrower->read({'borrowernumber' => $borrowernumber})->first; |
| 16 |
# show his name |
| 17 |
say $borrower->firstname; |
| 18 |
say $borrower->surname; |
| 19 |
# show the branchname, very easy !!! |
| 20 |
say $borrower->branchcode->branchname; |
| 21 |
# same thing with category |
| 22 |
say $borrower->categorycode->description; |
| 23 |
# now retrieve all items issued to this patron |
| 24 |
# note that each line result in 3 SQL queries being done |
| 25 |
# possible improvement => prefetch the link between |
| 26 |
foreach my $checkout ($borrower->issues->all) { |
| 27 |
# show the itemnumber |
| 28 |
say "Item currently checked-out:".$checkout->itemnumber->itemnumber; |
| 29 |
# show book title |
| 30 |
say "Item currently checked-out:".$checkout->itemnumber->biblioitemnumber->biblionumber->title; |
| 31 |
} |
| 32 |
foreach my $checkout ($borrower->old_issues->all) { |
| 33 |
# show the itemnumber |
| 34 |
say "Item previously checked-out:".$checkout->itemnumber->itemnumber; |
| 35 |
# show book title |
| 36 |
say "Item previously checked-out:".$checkout->itemnumber->biblioitemnumber->biblionumber->title; |
| 37 |
} |
| 38 |
|
| 39 |
#use Data::Dumper; |
| 40 |
# get 1st categorycode |
| 41 |
#say "Fetching 1st categorycode"; |
| 42 |
#my $branch=Koha::BusinessLogic::Branch2->read({'branchcode' => 'MAURES'})->first; |
| 43 |
#say $branch->branchname; |
| 44 |
#my $branchrelation = $branch->branchrelations->first; |
| 45 |
#say "CODE".$branchrelation->categorycode->categorycode; |
| 46 |
# this also add a SQL query, why ? |
| 47 |
#say "BRANCH".$branchrelation->branchcode->branchcode; |
| 48 |
|
| 49 |
# |
| 50 |
#say Koha::BusinessLogic::Branch2->read({'branchcode' => 'TEST'})->first->branchrelations->first->categorycode->categorycode; |
| 51 |
# the following line add 3 queries => no caching at all |
| 52 |
#say Koha::BusinessLogic::Branch2->read({'branchcode' => 'TEST'})->first->branchrelations->first->branchcode->branchcode; |
| 53 |
|
| 54 |
# get all categorycodes |
| 55 |
#say "Fetching all categorycodes"; |
| 56 |
#foreach (Koha::BusinessLogic::Branch2->read({'branchcode' => 'TEST'})->first->branchrelations->all) { |
| 57 |
# say $_->categorycode->categorycode; |
| 58 |
#} |
| 59 |
|
| 60 |
# how many SQL queries did mysql recieve after this script is executed |
| 61 |
my (undef, $after) = split ' ',`mysql -e "show status"|grep Queries`; |
| 62 |
# the difference between before and after tell us how many queries have been made |
| 63 |
say "Total queries: ".($after-$before-3); # -3 is the number of queries "show status" itself requires |
| 64 |
|
| 65 |
# testing column = it does not require any SQL query, ++ ! |
| 66 |
#my $schema = Koha::Schema->connect( |
| 67 |
# 'dbi:mysql:dbname='.C4::Context->config("database"), |
| 68 |
# C4::Context->config("user"), |
| 69 |
# C4::Context->config("pass"), |
| 70 |
# { AutoCommit => 1, |
| 71 |
# #cursor_class => 'DBIx::Class::Cursor::Cached', |
| 72 |
# }, |
| 73 |
# ); |
| 74 |
#(undef, $before) = split ' ',`mysql -e "show status"|grep Queries`; |
| 75 |
#my @temp = $schema->source('Branch')->columns; |
| 76 |
#say @temp; |
| 77 |
#(undef, $after) = split ' ',`mysql -e "show status"|grep Queries`; |
| 78 |
## the difference between before and after tell us how many queries have been made |
| 79 |
#say "Total queries for columns: ".($after-$before-3); # -3 is the number of queries "show status" itself requires |
| 80 |
# |