File | /data/SimpleDB-Class/author.t/../lib/SimpleDB/Class/ResultSet.pm |
Statements Executed | 644 |
Statement Execution Time | 3.58ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
23 | 10 | 2 | 1.80ms | 602ms | next | SimpleDB::Class::ResultSet::
10 | 2 | 1 | 770µs | 848ms | fetch_result | SimpleDB::Class::ResultSet::
4 | 4 | 1 | 248µs | 316ms | count | SimpleDB::Class::ResultSet::
1 | 1 | 1 | 111µs | 391ms | paginate | SimpleDB::Class::ResultSet::
1 | 1 | 1 | 32µs | 2.54ms | BEGIN@21 | SimpleDB::Class::ResultSet::
7 | 1 | 1 | 20µs | 20µs | __ANON__[../lib/SimpleDB/Class/ResultSet.pm:109] | SimpleDB::Class::ResultSet::
1 | 1 | 1 | 13µs | 112µs | BEGIN@520 | SimpleDB::Class::ResultSet::
1 | 1 | 1 | 5µs | 5µs | BEGIN@22 | SimpleDB::Class::ResultSet::
0 | 0 | 0 | 0s | 0s | __ANON__[../lib/SimpleDB/Class/ResultSet.pm:182] | SimpleDB::Class::ResultSet::
0 | 0 | 0 | 0s | 0s | delete | SimpleDB::Class::ResultSet::
0 | 0 | 0 | 0s | 0s | search | SimpleDB::Class::ResultSet::
0 | 0 | 0 | 0s | 0s | to_array_ref | SimpleDB::Class::ResultSet::
0 | 0 | 0 | 0s | 0s | update | SimpleDB::Class::ResultSet::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package SimpleDB::Class::ResultSet; | ||||
2 | |||||
3 | =head1 NAME | ||||
4 | |||||
5 | SimpleDB::Class::ResultSet - An iterator of items from a domain. | ||||
6 | |||||
7 | =head1 DESCRIPTION | ||||
8 | |||||
9 | This class is an iterator to walk to the items passed back from a query. | ||||
10 | |||||
11 | B<Warning:> Once you have a result set and you start calling methods on it, it will begin iterating over the result set. Therefore you can't call both C<next> and C<search>, or any other combinations of methods on an existing result set. | ||||
12 | |||||
13 | B<Warning:> If you call a method like C<search> on a result set which causes another query to be run, know that the original result set must be very small. This is because there is a limit of 20 comparisons per request as a limitation of SimpleDB. | ||||
14 | |||||
15 | =head1 METHODS | ||||
16 | |||||
17 | The following methods are available from this class. | ||||
18 | |||||
19 | =cut | ||||
20 | |||||
21 | 3 | 30µs | 2 | 5.05ms | # spent 2.54ms (32µs+2.51) within SimpleDB::Class::ResultSet::BEGIN@21 which was called
# once (32µs+2.51ms) by SimpleDB::Class::Domain::BEGIN@19 at line 21 # spent 2.54ms making 1 call to SimpleDB::Class::ResultSet::BEGIN@21
# spent 2.51ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389] |
22 | 3 | 994µs | 1 | 5µs | # spent 5µs within SimpleDB::Class::ResultSet::BEGIN@22 which was called
# once (5µs+0s) by SimpleDB::Class::Domain::BEGIN@19 at line 22 # spent 5µs making 1 call to SimpleDB::Class::ResultSet::BEGIN@22 |
23 | |||||
24 | #-------------------------------------------------------- | ||||
25 | |||||
26 | =head2 new ( params ) | ||||
27 | |||||
28 | Constructor. | ||||
29 | |||||
30 | =head3 params | ||||
31 | |||||
32 | A hash. | ||||
33 | |||||
34 | =head4 simpledb | ||||
35 | |||||
36 | Required. A L<SimpleDB::Class> object. | ||||
37 | |||||
38 | =head4 item_class | ||||
39 | |||||
40 | Required. A L<SimpleDB::Class::Item> subclass name. | ||||
41 | |||||
42 | =head4 result | ||||
43 | |||||
44 | A result as returned from the send_request() method from L<SimpleDB::Client>. Either this or a where is required. | ||||
45 | |||||
46 | =head4 where | ||||
47 | |||||
48 | A where clause as defined in L<SimpleDB::Class::SQL>. Either this or a result is required. | ||||
49 | |||||
50 | =head4 order_by | ||||
51 | |||||
52 | An order_by clause as defined in L<SimpleDB::Class::SQL>. Optional. | ||||
53 | |||||
54 | =head4 limit | ||||
55 | |||||
56 | A limit clause as defined in L<SimpleDB::Class::SQL>. Optional. B<NOTE:>SimpleDB defines a limit as the number of results to limit to each Next Token, but SimpleDB::Class::ResultSet enforces the limit to be more like a traditional relational database, so calling C<next()> after the limit will return C<undef> just as if there were no more results left to display. | ||||
57 | |||||
58 | =head4 consistent | ||||
59 | |||||
60 | A boolean that if set true will get around Eventual Consistency, but at a reduced performance. Optional. | ||||
61 | |||||
62 | =head4 set | ||||
63 | |||||
64 | A hash reference of attribute names and values, which will be set on the item as C<next> is called. Doing so helps to prevent stale object references. | ||||
65 | |||||
66 | =cut | ||||
67 | |||||
68 | #-------------------------------------------------------- | ||||
69 | |||||
70 | =head2 item_class ( ) | ||||
71 | |||||
72 | Returns the item_class passed into the constructor. | ||||
73 | |||||
74 | =cut | ||||
75 | |||||
76 | 1 | 3µs | 1 | 1.45ms | has item_class => ( # spent 1.45ms making 1 call to Moose::has |
77 | is => 'ro', | ||||
78 | isa => 'ClassName', | ||||
79 | required => 1, | ||||
80 | ); | ||||
81 | |||||
82 | 1 | 2µs | 1 | 59.8ms | with 'SimpleDB::Class::Role::Itemized'; # spent 59.8ms making 1 call to Moose::with |
83 | |||||
84 | #-------------------------------------------------------- | ||||
85 | |||||
86 | =head2 consistent ( ) | ||||
87 | |||||
88 | Returns the consistent value passed into the constructor. | ||||
89 | |||||
90 | =cut | ||||
91 | |||||
92 | 1 | 4µs | 1 | 1.70ms | has consistent => ( # spent 1.70ms making 1 call to Moose::has |
93 | is => 'ro', | ||||
94 | isa => 'Bool', | ||||
95 | default => 0, | ||||
96 | ); | ||||
97 | |||||
98 | #-------------------------------------------------------- | ||||
99 | |||||
100 | =head2 set ( ) | ||||
101 | |||||
102 | Returns the set value passed into the constructor. | ||||
103 | |||||
104 | =cut | ||||
105 | |||||
106 | has set => ( | ||||
107 | is => 'ro', | ||||
108 | isa => 'HashRef', | ||||
109 | 7 | 25µs | # spent 20µs within SimpleDB::Class::ResultSet::__ANON__[../lib/SimpleDB/Class/ResultSet.pm:109] which was called 7 times, avg 3µs/call:
# 7 times (20µs+0s) by Class::MOP::Mixin::AttributeCore::default at line 53 of Class/MOP/Mixin/AttributeCore.pm, avg 3µs/call | ||
110 | 1 | 6µs | 1 | 1.10ms | ); # spent 1.10ms making 1 call to Moose::has |
111 | |||||
112 | #-------------------------------------------------------- | ||||
113 | |||||
114 | =head2 where ( ) | ||||
115 | |||||
116 | Returns the where passed into the constructor. | ||||
117 | |||||
118 | =cut | ||||
119 | |||||
120 | 1 | 2µs | 1 | 940µs | has where => ( # spent 940µs making 1 call to Moose::has |
121 | is => 'ro', | ||||
122 | isa => 'HashRef', | ||||
123 | ); | ||||
124 | |||||
125 | #-------------------------------------------------------- | ||||
126 | |||||
127 | =head2 order_by ( ) | ||||
128 | |||||
129 | Returns the order_by passed into the constructor. | ||||
130 | |||||
131 | =cut | ||||
132 | |||||
133 | 1 | 2µs | 1 | 3.19ms | has order_by => ( # spent 3.19ms making 1 call to Moose::has |
134 | is => 'ro', | ||||
135 | isa => 'Str | ArrayRef[Str]', | ||||
136 | predicate => 'has_order_by', | ||||
137 | ); | ||||
138 | |||||
139 | #-------------------------------------------------------- | ||||
140 | |||||
141 | =head2 limit ( ) | ||||
142 | |||||
143 | Returns the limit passed into the constructor. | ||||
144 | |||||
145 | =cut | ||||
146 | |||||
147 | 1 | 2µs | 1 | 1.50ms | has limit => ( # spent 1.50ms making 1 call to Moose::has |
148 | is => 'rw', | ||||
149 | isa => 'Str', | ||||
150 | predicate => 'has_limit', | ||||
151 | ); | ||||
152 | |||||
153 | #-------------------------------------------------------- | ||||
154 | |||||
155 | =head2 simpledb ( ) | ||||
156 | |||||
157 | Returns the simpledb passed into the constructor. | ||||
158 | |||||
159 | =cut | ||||
160 | |||||
161 | 1 | 2µs | 1 | 914µs | has simpledb => ( # spent 914µs making 1 call to Moose::has |
162 | is => 'ro', | ||||
163 | required => 1, | ||||
164 | ); | ||||
165 | |||||
166 | #-------------------------------------------------------- | ||||
167 | |||||
168 | =head2 result ( ) | ||||
169 | |||||
170 | Returns the result passed into the constructor, or the one generated by fetch_result() if a where is passed into the constructor. | ||||
171 | |||||
172 | =head2 has_result () | ||||
173 | |||||
174 | A boolean indicating whether a result was passed into the constructor, or generated by fetch_result(). | ||||
175 | |||||
176 | =cut | ||||
177 | |||||
178 | has result => ( | ||||
179 | is => 'rw', | ||||
180 | isa => 'HashRef', | ||||
181 | predicate => 'has_result', | ||||
182 | default => sub {{}}, | ||||
183 | 1 | 6µs | 1 | 1.55ms | lazy => 1, # spent 1.55ms making 1 call to Moose::has |
184 | ); | ||||
185 | |||||
186 | #-------------------------------------------------------- | ||||
187 | |||||
188 | =head2 iterator ( ) | ||||
189 | |||||
190 | Returns an integer which represents the current position in the result set as traversed by C<next()>. | ||||
191 | |||||
192 | =cut | ||||
193 | |||||
194 | 1 | 2µs | 1 | 1.17ms | has iterator => ( # spent 1.17ms making 1 call to Moose::has |
195 | is => 'rw', | ||||
196 | isa => 'Int', | ||||
197 | default => 0, | ||||
198 | ); | ||||
199 | |||||
200 | #-------------------------------------------------------- | ||||
201 | |||||
202 | =head2 limit_counter ( ) | ||||
203 | |||||
204 | Returns an integer representing how many items have been traversed so far by C<next()>. When this reaches the value of C<limit> then no more results will be returned by C<next()>. | ||||
205 | |||||
206 | =cut | ||||
207 | |||||
208 | 1 | 2µs | 1 | 1.21ms | has limit_counter => ( # spent 1.21ms making 1 call to Moose::has |
209 | is => 'rw', | ||||
210 | isa => 'Int', | ||||
211 | default => 0, | ||||
212 | ); | ||||
213 | |||||
214 | #-------------------------------------------------------- | ||||
215 | |||||
216 | =head2 fetch_result ( [ next ] ) | ||||
217 | |||||
218 | Fetches a result, based on a where clause passed into a constructor, and then makes it accessible via the C<result()> method. | ||||
219 | |||||
220 | =head3 next | ||||
221 | |||||
222 | A next token, in order to fetch the next part of a result set. | ||||
223 | |||||
224 | =cut | ||||
225 | |||||
226 | sub fetch_result { | ||||
227 | 10 | 12µs | my ($self, $next) = @_; | ||
228 | 10 | 106µs | 30 | 98µs | my %sql_params = ( # spent 41µs making 10 calls to SimpleDB::Class::ResultSet::where, avg 4µs/call
# spent 32µs making 10 calls to SimpleDB::Class::ResultSet::item_class, avg 3µs/call
# spent 25µs making 10 calls to SimpleDB::Class::ResultSet::simpledb, avg 3µs/call |
229 | item_class => $self->item_class, | ||||
230 | simpledb => $self->simpledb, | ||||
231 | where => $self->where, | ||||
232 | ); | ||||
233 | 10 | 41µs | 12 | 39µs | if ($self->has_order_by) { # spent 32µs making 10 calls to SimpleDB::Class::ResultSet::has_order_by, avg 3µs/call
# spent 8µs making 2 calls to SimpleDB::Class::ResultSet::order_by, avg 4µs/call |
234 | $sql_params{order_by} = $self->order_by; | ||||
235 | } | ||||
236 | 10 | 26µs | 12 | 19µs | if ($self->has_limit) { # spent 14µs making 10 calls to SimpleDB::Class::ResultSet::has_limit, avg 1µs/call
# spent 5µs making 2 calls to SimpleDB::Class::ResultSet::limit, avg 3µs/call |
237 | $sql_params{limit} = $self->limit; | ||||
238 | } | ||||
239 | 10 | 58µs | 10 | 327µs | my $select = SimpleDB::Class::SQL->new(%sql_params); # spent 327µs making 10 calls to SimpleDB::Class::SQL::new, avg 33µs/call |
240 | 10 | 58µs | 10 | 3.69ms | my %params = (SelectExpression => $select->to_sql); # spent 3.69ms making 10 calls to SimpleDB::Class::SQL::to_sql, avg 369µs/call |
241 | 10 | 48µs | 10 | 41µs | if ($self->consistent) { # spent 41µs making 10 calls to SimpleDB::Class::ResultSet::consistent, avg 4µs/call |
242 | $params{ConsistentRead} = 'true'; | ||||
243 | } | ||||
244 | |||||
245 | # if we're fetching and we already have a result, we can assume we're getting the next batch | ||||
246 | 10 | 7µs | if (defined $next && $next ne '') { | ||
247 | $params{NextToken} = $next; | ||||
248 | } | ||||
249 | |||||
250 | 10 | 81µs | 30 | 843ms | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 843ms making 10 calls to SimpleDB::Client::send_request, avg 84.3ms/call
# spent 51µs making 10 calls to SimpleDB::Class::http, avg 5µs/call
# spent 17µs making 10 calls to SimpleDB::Class::ResultSet::simpledb, avg 2µs/call |
251 | 10 | 55µs | 10 | 197µs | $self->result($result); # spent 197µs making 10 calls to SimpleDB::Class::ResultSet::result, avg 20µs/call |
252 | 10 | 156µs | return $result; | ||
253 | } | ||||
254 | |||||
255 | #-------------------------------------------------------- | ||||
256 | |||||
257 | =head2 count ( [ options ] ) | ||||
258 | |||||
259 | Counts the items in the result set. Returns an integer. | ||||
260 | |||||
261 | =head3 options | ||||
262 | |||||
263 | A hash of extra options you can pass to modify the count. | ||||
264 | |||||
265 | =head4 where | ||||
266 | |||||
267 | A where clause as defined by L<SimpleDB::Class::SQL>. If this is specified, then an additional query is executed before counting the items in the result set. | ||||
268 | |||||
269 | =cut | ||||
270 | |||||
271 | # spent 316ms (248µs+315) within SimpleDB::Class::ResultSet::count which was called 4 times, avg 78.9ms/call:
# once (118µs+112ms) by main::RUNTIME at line 71 of 05.Domain_and_Item.t
# once (47µs+76.6ms) by main::RUNTIME at line 69 of 05.Domain_and_Item.t
# once (57µs+70.2ms) by main::RUNTIME at line 73 of 05.Domain_and_Item.t
# once (26µs+56.8ms) by main::RUNTIME at line 74 of 05.Domain_and_Item.t | ||||
272 | 4 | 4µs | my ($self, %options) = @_; | ||
273 | 4 | 1µs | my @ids; | ||
274 | 4 | 134µs | 28 | 262ms | while (my $item = $self->next) { # spent 261ms making 12 calls to SimpleDB::Class::ResultSet::next, avg 21.8ms/call
# spent 445µs making 8 calls to Moose::Object::DESTROY, avg 56µs/call
# spent 34µs making 8 calls to SimpleDB::Class::Item::id, avg 4µs/call |
275 | push @ids, $item->id; | ||||
276 | } | ||||
277 | 4 | 3µs | if ($options{where}) { | ||
278 | 1 | 4µs | my $clauses = { | ||
279 | 'itemName()' => ['in',@ids], | ||||
280 | '-and' => $options{where}, | ||||
281 | }; | ||||
282 | 1 | 9µs | 3 | 37µs | my $select = SimpleDB::Class::SQL->new( # spent 33µs making 1 call to SimpleDB::Class::SQL::new
# spent 2µs making 1 call to SimpleDB::Class::ResultSet::item_class
# spent 1µs making 1 call to SimpleDB::Class::ResultSet::simpledb |
283 | item_class => $self->item_class, | ||||
284 | simpledb => $self->simpledb, | ||||
285 | where => $clauses, | ||||
286 | output => 'count(*)', | ||||
287 | ); | ||||
288 | 1 | 6µs | 1 | 427µs | my %params = ( SelectExpression => $select->to_sql ); # spent 427µs making 1 call to SimpleDB::Class::SQL::to_sql |
289 | 1 | 5µs | 1 | 4µs | if ($self->consistent) { # spent 4µs making 1 call to SimpleDB::Class::ResultSet::consistent |
290 | $params{ConsistentRead} = 'true'; | ||||
291 | } | ||||
292 | 1 | 9µs | 3 | 53.4ms | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 53.4ms making 1 call to SimpleDB::Client::send_request
# spent 5µs making 1 call to SimpleDB::Class::http
# spent 1µs making 1 call to SimpleDB::Class::ResultSet::simpledb |
293 | 1 | 18µs | return $result->{SelectResult}{Item}[0]{Attribute}{Value}; | ||
294 | } | ||||
295 | else { | ||||
296 | 3 | 17µs | return scalar @ids; | ||
297 | } | ||||
298 | } | ||||
299 | |||||
300 | #-------------------------------------------------------- | ||||
301 | |||||
302 | =head2 search ( options ) | ||||
303 | |||||
304 | Just like L<SimpleDB::Class::Domain/"search">, but searches within the confines of the current result set, and then returns a new result set. | ||||
305 | |||||
306 | =head3 options | ||||
307 | |||||
308 | A hash of extra options to modify the search. | ||||
309 | |||||
310 | =head4 where | ||||
311 | |||||
312 | A where clause as defined by L<SimpleDB::Class::SQL>. | ||||
313 | |||||
314 | =cut | ||||
315 | |||||
316 | sub search { | ||||
317 | my ($self, %options) = @_; | ||||
318 | my @ids; | ||||
319 | while (my $item = $self->next) { | ||||
320 | push @ids, $item->id; | ||||
321 | } | ||||
322 | my $clauses = { | ||||
323 | 'itemName()' => ['in',@ids], | ||||
324 | '-and' => $options{where}, | ||||
325 | }; | ||||
326 | return $self->new( | ||||
327 | simpledb => $self->simpledb, | ||||
328 | item_class => $self->item_class, | ||||
329 | where => $clauses, | ||||
330 | consistent => $self->consistent, | ||||
331 | set => $self->set, | ||||
332 | ); | ||||
333 | } | ||||
334 | |||||
335 | #-------------------------------------------------------- | ||||
336 | |||||
337 | =head2 update ( attributes ) | ||||
338 | |||||
339 | Calls C<update> and then C<put> on all the items in the result set. | ||||
340 | |||||
341 | =head3 attributes | ||||
342 | |||||
343 | A hash reference containing name/value pairs to update in each item. | ||||
344 | |||||
345 | =cut | ||||
346 | |||||
347 | sub update { | ||||
348 | my ($self, $attributes) = @_; | ||||
349 | while (my $item = $self->next) { | ||||
350 | $item->update($attributes)->put; | ||||
351 | } | ||||
352 | } | ||||
353 | |||||
354 | #-------------------------------------------------------- | ||||
355 | |||||
356 | =head2 delete ( ) | ||||
357 | |||||
358 | Calls C<delete> on all the items in the result set. | ||||
359 | |||||
360 | =cut | ||||
361 | |||||
362 | sub delete { | ||||
363 | my ($self) = @_; | ||||
364 | while (my $item = $self->next) { | ||||
365 | $item->delete; | ||||
366 | } | ||||
367 | } | ||||
368 | |||||
369 | #-------------------------------------------------------- | ||||
370 | |||||
371 | =head2 paginate ( items_per_page, page_number ) | ||||
372 | |||||
373 | Use on a new result set to fast forward to the desired data. After you've paginated, you can call C<next> to start fetching your data. Returns a reference to the result set for easy method chaining. | ||||
374 | |||||
375 | B<NOTE:> Unless you've already set a limit, the limit for this result set will be set to C<items_per_page> as a convenience. | ||||
376 | |||||
377 | =head3 items_per_page | ||||
378 | |||||
379 | An integer representing how many items you're fetching/displaying per page. | ||||
380 | |||||
381 | =head3 page_number | ||||
382 | |||||
383 | An integer representing what page number you'd like to skip ahead to. | ||||
384 | |||||
385 | =cut | ||||
386 | |||||
387 | # spent 391ms (111µs+391) within SimpleDB::Class::ResultSet::paginate which was called
# once (111µs+391ms) by main::RUNTIME at line 118 of 05.Domain_and_Item.t | ||||
388 | 1 | 1µs | my ($self, $items_per_page, $page_number) = @_; | ||
389 | 1 | 6µs | 2 | 14µs | unless ($self->has_limit) { # spent 11µs making 1 call to SimpleDB::Class::ResultSet::limit
# spent 3µs making 1 call to SimpleDB::Class::ResultSet::has_limit |
390 | $self->limit($items_per_page); | ||||
391 | } | ||||
392 | 1 | 1µs | my $limit = ($items_per_page * ($page_number - 1)); | ||
393 | 1 | 400ns | return $self if $limit == 0; | ||
394 | 1 | 13µs | 3 | 10µs | my %sql_params = ( # spent 4µs making 1 call to SimpleDB::Class::ResultSet::where
# spent 4µs making 1 call to SimpleDB::Class::ResultSet::item_class
# spent 3µs making 1 call to SimpleDB::Class::ResultSet::simpledb |
395 | item_class => $self->item_class, | ||||
396 | simpledb => $self->simpledb, | ||||
397 | where => $self->where, | ||||
398 | output => 'count(*)', | ||||
399 | limit => $limit, | ||||
400 | ); | ||||
401 | 1 | 7µs | 2 | 7µs | if ($self->has_order_by) { # spent 4µs making 1 call to SimpleDB::Class::ResultSet::order_by
# spent 3µs making 1 call to SimpleDB::Class::ResultSet::has_order_by |
402 | $sql_params{order_by} = $self->order_by; | ||||
403 | } | ||||
404 | 1 | 8µs | 1 | 33µs | my $select = SimpleDB::Class::SQL->new(%sql_params); # spent 33µs making 1 call to SimpleDB::Class::SQL::new |
405 | 1 | 6µs | 1 | 538µs | my %params = (SelectExpression => $select->to_sql); # spent 538µs making 1 call to SimpleDB::Class::SQL::to_sql |
406 | 1 | 5µs | 1 | 4µs | if ($self->consistent) { # spent 4µs making 1 call to SimpleDB::Class::ResultSet::consistent |
407 | $params{ConsistentRead} = 'true'; | ||||
408 | } | ||||
409 | 1 | 10µs | 3 | 80.8ms | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 80.8ms making 1 call to SimpleDB::Client::send_request
# spent 5µs making 1 call to SimpleDB::Class::http
# spent 1µs making 1 call to SimpleDB::Class::ResultSet::simpledb |
410 | 1 | 6µs | 1 | 309ms | $self->fetch_result($result->{SelectResult}{NextToken}); # spent 309ms making 1 call to SimpleDB::Class::ResultSet::fetch_result |
411 | 1 | 22µs | return $self; | ||
412 | } | ||||
413 | |||||
414 | |||||
415 | #-------------------------------------------------------- | ||||
416 | |||||
417 | =head2 next () | ||||
418 | |||||
419 | Returns the next result in the result set. Also fetches th next partial result set if there's a next token in the first result set and you've iterated through the first partial set. | ||||
420 | |||||
421 | =cut | ||||
422 | |||||
423 | # spent 602ms (1.80+600) within SimpleDB::Class::ResultSet::next which was called 23 times, avg 26.2ms/call:
# 12 times (725µs+260ms) by SimpleDB::Class::ResultSet::count at line 274, avg 21.8ms/call
# 3 times (236µs+10.5ms) by main::RUNTIME at line 135 of 05.Domain_and_Item.t, avg 3.57ms/call
# once (104µs+71.6ms) by main::RUNTIME at line 59 of 05.Domain_and_Item.t
# once (128µs+66.6ms) by main::RUNTIME at line 88 of 05.Domain_and_Item.t
# once (104µs+64.0ms) by main::RUNTIME at line 53 of 05.Domain_and_Item.t
# once (139µs+63.9ms) by main::RUNTIME at line 134 of 05.Domain_and_Item.t
# once (89µs+53.9ms) by main::RUNTIME at line 62 of 05.Domain_and_Item.t
# once (151µs+4.60ms) by main::RUNTIME at line 123 of 05.Domain_and_Item.t
# once (66µs+2.38ms) by main::RUNTIME at line 63 of 05.Domain_and_Item.t
# once (55µs+2.22ms) by main::RUNTIME at line 54 of 05.Domain_and_Item.t | ||||
424 | 23 | 18µs | my ($self) = @_; | ||
425 | |||||
426 | # handle limit counter | ||||
427 | 23 | 90µs | 33 | 94µs | if ($self->has_limit && $self->limit_counter >= $self->limit) { # spent 64µs making 23 calls to SimpleDB::Class::ResultSet::has_limit, avg 3µs/call
# spent 15µs making 5 calls to SimpleDB::Class::ResultSet::limit_counter, avg 3µs/call
# spent 15µs making 5 calls to SimpleDB::Class::ResultSet::limit, avg 3µs/call |
428 | return undef; | ||||
429 | } | ||||
430 | |||||
431 | # get the current results | ||||
432 | 22 | 104µs | 44 | 539ms | my $result = ($self->has_result) ? $self->result : $self->fetch_result; # spent 539ms making 9 calls to SimpleDB::Class::ResultSet::fetch_result, avg 59.9ms/call
# spent 55µs making 22 calls to SimpleDB::Class::ResultSet::has_result, avg 2µs/call
# spent 34µs making 13 calls to SimpleDB::Class::ResultSet::result, avg 3µs/call |
433 | 22 | 16µs | my $items = []; | ||
434 | 22 | 48µs | if (ref $result->{SelectResult}{Item} eq 'ARRAY') { | ||
435 | $items = $result->{SelectResult}{Item}; | ||||
436 | } | ||||
437 | |||||
438 | # fetch more results if needed | ||||
439 | 22 | 62µs | 22 | 70µs | my $iterator = $self->iterator; # spent 70µs making 22 calls to SimpleDB::Class::ResultSet::iterator, avg 3µs/call |
440 | 22 | 14µs | if ($iterator >= scalar @{$items}) { | ||
441 | 4 | 4µs | if (exists $result->{SelectResult}{NextToken}) { | ||
442 | $self->iterator(0); | ||||
443 | $iterator = 0; | ||||
444 | $result = $self->fetch_result($result->{SelectResult}{NextToken}); | ||||
445 | $items = $result->{SelectResult}{Item}; | ||||
446 | } | ||||
447 | else { | ||||
448 | 4 | 8µs | return undef; | ||
449 | } | ||||
450 | } | ||||
451 | |||||
452 | # iterate | ||||
453 | 18 | 13µs | my $item = $items->[$iterator]; | ||
454 | 18 | 5µs | return undef unless defined $item; | ||
455 | 18 | 4µs | $iterator++; | ||
456 | 18 | 22µs | 18 | 281µs | $self->iterator($iterator); # spent 281µs making 18 calls to SimpleDB::Class::ResultSet::iterator, avg 16µs/call |
457 | |||||
458 | # make the item object | ||||
459 | 18 | 51µs | 18 | 50µs | my $db = $self->simpledb; # spent 50µs making 18 calls to SimpleDB::Class::ResultSet::simpledb, avg 3µs/call |
460 | 18 | 183µs | 54 | 312µs | my $domain_name = $db->add_domain_prefix($self->item_class->domain_name); # spent 209µs making 18 calls to SimpleDB::Class::add_domain_prefix, avg 12µs/call
# spent 54µs making 18 calls to SimpleDB::Class::ResultSet::item_class, avg 3µs/call
# spent 44µs making 17 calls to Foo::Domain::domain_name, avg 3µs/call
# spent 4µs making 1 call to Foo::Child::domain_name |
461 | 18 | 51µs | 18 | 82µs | my $cache = $db->cache; # spent 82µs making 18 calls to SimpleDB::Class::cache, avg 5µs/call |
462 | ## fetch from cache even though we've already pulled it back from the db, because the one in cache | ||||
463 | ## might be more up to date than the one from the DB | ||||
464 | 36 | 81µs | 18 | 18.4ms | my $attributes = eval{$cache->get($domain_name, $item->{Name})}; # spent 18.4ms making 18 calls to SimpleDB::Class::Cache::get, avg 1.02ms/call |
465 | 18 | 3µs | my $e; | ||
466 | 18 | 2µs | my $itemobj; | ||
467 | 18 | 199µs | 51 | 26.9ms | if ($e = SimpleDB::Class::Exception::ObjectNotFound->caught) { # spent 26.5ms making 15 calls to SimpleDB::Class::Role::Itemized::instantiate_item, avg 1.77ms/call
# spent 361µs making 33 calls to Exception::Class::Base::caught, avg 11µs/call
# spent 6µs making 3 calls to Exception::Class::Base::__ANON__[Exception/Class/Base.pm:30], avg 2µs/call |
468 | 3 | 10µs | 3 | 12.7ms | $itemobj = $self->parse_item($item->{Name}, $item->{Attribute}); # spent 12.7ms making 3 calls to SimpleDB::Class::Role::Itemized::parse_item, avg 4.23ms/call |
469 | 3 | 2µs | if (defined $itemobj) { | ||
470 | 6 | 17µs | 6 | 1.59ms | eval{$cache->set($domain_name, $item->{Name}, $itemobj->to_hashref)}; # spent 1.01ms making 3 calls to SimpleDB::Class::Cache::set, avg 336µs/call
# spent 582µs making 3 calls to SimpleDB::Class::Item::to_hashref, avg 194µs/call |
471 | } | ||||
472 | } | ||||
473 | elsif ($e = SimpleDB::Class::Exception->caught) { | ||||
474 | warn $e->error; | ||||
475 | $e->rethrow; | ||||
476 | } | ||||
477 | elsif (defined $attributes) { | ||||
478 | $itemobj = $self->instantiate_item($attributes,$item->{Name}); | ||||
479 | } | ||||
480 | else { | ||||
481 | SimpleDB::Class::Exception->throw(error=>"An undefined error occured while fetching the item from cache."); | ||||
482 | } | ||||
483 | |||||
484 | # process the 'set' option | ||||
485 | 18 | 83µs | 18 | 68µs | my %set = %{$self->set}; # spent 68µs making 18 calls to SimpleDB::Class::ResultSet::set, avg 4µs/call |
486 | 18 | 34µs | foreach my $attribute (keys %set) { | ||
487 | 5 | 15µs | 5 | 21µs | $itemobj->$attribute( $set{$attribute} ); # spent 14µs making 4 calls to Foo::Domain::parent, avg 4µs/call
# spent 7µs making 1 call to Foo::Child::domain |
488 | } | ||||
489 | |||||
490 | # increment limit counter | ||||
491 | 18 | 80µs | 36 | 297µs | $self->limit_counter($self->limit_counter + 1); # spent 297µs making 36 calls to SimpleDB::Class::ResultSet::limit_counter, avg 8µs/call |
492 | |||||
493 | 18 | 205µs | return $itemobj; | ||
494 | } | ||||
495 | |||||
496 | #-------------------------------------------------------- | ||||
497 | |||||
498 | =head2 to_array_ref () | ||||
499 | |||||
500 | Returns an array reference containing all the objects in the result set. If the result set has already been partially walked, then only the remaining objects will be returned. | ||||
501 | |||||
502 | =cut | ||||
503 | |||||
504 | sub to_array_ref { | ||||
505 | my ($self) = @_; | ||||
506 | my @all; | ||||
507 | while (my $object = $self->next) { | ||||
508 | push @all, $object; | ||||
509 | } | ||||
510 | return \@all; | ||||
511 | } | ||||
512 | |||||
513 | |||||
514 | =head1 LEGAL | ||||
515 | |||||
516 | SimpleDB::Class is Copyright 2009-2010 Plain Black Corporation (L<http://www.plainblack.com/>) and is licensed under the same terms as Perl itself. | ||||
517 | |||||
518 | =cut | ||||
519 | |||||
520 | 3 | 52µs | 2 | 212µs | # spent 112µs (13+99) within SimpleDB::Class::ResultSet::BEGIN@520 which was called
# once (13µs+99µs) by SimpleDB::Class::Domain::BEGIN@19 at line 520 # spent 112µs making 1 call to SimpleDB::Class::ResultSet::BEGIN@520
# spent 99µs making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:478] |
521 | 1 | 79µs | 2 | 3.89ms | __PACKAGE__->meta->make_immutable; # spent 3.88ms making 1 call to Class::MOP::Class::make_immutable
# spent 12µs making 1 call to SimpleDB::Class::ResultSet::meta |