Profile of /data/SimpleDB-Class/author.t/../lib/SimpleDB/Class/Domain.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For 05.Domain_and_Item.t
Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:22:23 2010

File | /data/SimpleDB-Class/author.t/../lib/SimpleDB/Class/Domain.pm
Statements Executed | 286
Statement Execution Time | 3.36ms

Subroutines — ordered by exclusive time
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 1.30ms | 82.4ms | SimpleDB::Class::Domain::::BEGIN@19SimpleDB::Class::Domain::BEGIN@19
1 | 1 | 1 | 1.06ms | 115ms | SimpleDB::Class::Domain::::BEGIN@18SimpleDB::Class::Domain::BEGIN@18
6 | 6 | 2 | 524µs | 248ms | SimpleDB::Class::Domain::::findSimpleDB::Class::Domain::find
11 | 11 | 1 | 359µs | 3.88s | SimpleDB::Class::Domain::::insertSimpleDB::Class::Domain::insert
10 | 8 | 2 | 234µs | 1.71ms | SimpleDB::Class::Domain::::searchSimpleDB::Class::Domain::search
2 | 2 | 1 | 183µs | 157ms | SimpleDB::Class::Domain::::maxSimpleDB::Class::Domain::max
2 | 2 | 1 | 138µs | 129ms | SimpleDB::Class::Domain::::minSimpleDB::Class::Domain::min
2 | 2 | 1 | 135µs | 140ms | SimpleDB::Class::Domain::::countSimpleDB::Class::Domain::count
7 | 1 | 1 | 116µs | 221µs | SimpleDB::Class::Domain::::__ANON__[../lib/SimpleDB/Class/Domain.pm:59]SimpleDB::Class::Domain::__ANON__[../lib/SimpleDB/Class/Domain.pm:59]
3 | 3 | 1 | 100µs | 5.58s | SimpleDB::Class::Domain::::deleteSimpleDB::Class::Domain::delete
3 | 3 | 1 | 88µs | 4.05s | SimpleDB::Class::Domain::::createSimpleDB::Class::Domain::create
1 | 1 | 1 | 85µs | 53.1ms | SimpleDB::Class::Domain::::fetch_idsSimpleDB::Class::Domain::fetch_ids
1 | 1 | 1 | 32µs | 2.60ms | SimpleDB::Class::Domain::::BEGIN@17SimpleDB::Class::Domain::BEGIN@17
1 | 1 | 1 | 16µs | 16µs | SimpleDB::Class::Domain::::BEGIN@20SimpleDB::Class::Domain::BEGIN@20
1 | 1 | 1 | 10µs | 129µs | SimpleDB::Class::Domain::::BEGIN@458SimpleDB::Class::Domain::BEGIN@458

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package SimpleDB::Class::Domain;
2 |  |  |  |  |
3 |  |  |  |  | =head1 NAME
4 |  |  |  |  |
5 |  |  |  |  | SimpleDB::Class::Domain - A schematic representation of a SimpleDB domain.
6 |  |  |  |  |
7 |  |  |  |  | =head1 DESCRIPTION
8 |  |  |  |  |
9 |  |  |  |  | A subclass of this class is created for each domain in SimpleDB with it's name, attributes, and relationships.
10 |  |  |  |  |
11 |  |  |  |  | =head1 METHODS
12 |  |  |  |  |
13 |  |  |  |  | The following methods are available from this class.
14 |  |  |  |  |
15 |  |  |  |  | =cut
16 |  |  |  |  |
17 | 3 | 33µs | 2 | 5.18ms | # spent 2.60ms (32µs+2.57) within SimpleDB::Class::Domain::BEGIN@17 which was called # once (32µs+2.57ms) by SimpleDB::Class::BEGIN@141 at line 17 use Moose; # spent 2.60ms making 1 call to SimpleDB::Class::Domain::BEGIN@17 # spent 2.57ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:389]
18 | 3 | 155µs | 1 | 115ms | # spent 115ms (1.06+114) within SimpleDB::Class::Domain::BEGIN@18 which was called # once (1.06ms+114ms) by SimpleDB::Class::BEGIN@141 at line 18 use SimpleDB::Class::SQL; # spent 115ms making 1 call to SimpleDB::Class::Domain::BEGIN@18
19 | 3 | 159µs | 1 | 82.4ms | # spent 82.4ms (1.30+81.1) within SimpleDB::Class::Domain::BEGIN@19 which was called # once (1.30ms+81.1ms) by SimpleDB::Class::BEGIN@141 at line 19 use SimpleDB::Class::ResultSet; # spent 82.4ms making 1 call to SimpleDB::Class::Domain::BEGIN@19
20 | 3 | 1.27ms | 1 | 16µs | # spent 16µs within SimpleDB::Class::Domain::BEGIN@20 which was called # once (16µs+0s) by SimpleDB::Class::BEGIN@141 at line 20 use SimpleDB::Class::Exception; # spent 16µs making 1 call to SimpleDB::Class::Domain::BEGIN@20
21 |  |  |  |  |
22 |  |  |  |  |
23 |  |  |  |  | #--------------------------------------------------------
24 |  |  |  |  |
25 |  |  |  |  | =head2 new ( params )
26 |  |  |  |  |
27 |  |  |  |  | Constructor. Normally you should never call this method yourself, instead use the domain() method in L<SimpleDB::Class>.
28 |  |  |  |  |
29 |  |  |  |  | =head3 params
30 |  |  |  |  |
31 |  |  |  |  | A hash containing the parameters needed to construct this object.
32 |  |  |  |  |
33 |  |  |  |  | =head4 simpledb
34 |  |  |  |  |
35 |  |  |  |  | Required. A reference to a L<SimpleDB::Class> object.
36 |  |  |  |  |
37 |  |  |  |  | =head4 name
38 |  |  |  |  |
39 |  |  |  |  | Required. The SimpleDB domain name associated with this class.
40 |  |  |  |  |
41 |  |  |  |  | =cut
42 |  |  |  |  |
43 |  |  |  |  |
44 |  |  |  |  | #--------------------------------------------------------
45 |  |  |  |  |
46 |  |  |  |  | =head2 item_class ( )
47 |  |  |  |  |
48 |  |  |  |  | Returns the L<SimpleDB::Class::Item> subclass name passed into the constructor.
49 |  |  |  |  |
50 |  |  |  |  | =cut
51 |  |  |  |  |
52 |  |  |  |  | has item_class => (
53 |  |  |  |  | is => 'ro',
54 |  |  |  |  | isa => 'Str',
55 |  |  |  |  | required => 1,
56 |  |  |  |  | # spent 221µs (116+105) within SimpleDB::Class::Domain::__ANON__[../lib/SimpleDB/Class/Domain.pm:59] which was called 7 times, avg 32µs/call: # 7 times (116µs+105µs) by SimpleDB::Class::Domain::new at line 32 of generated method (unknown origin), avg 32µs/call trigger => sub {
57 | 14 | 86µs |  |  | my ($self, $item, $old) = @_;
58 |  |  |  |  | $self->name($item->domain_name); # spent 84µs making 7 calls to SimpleDB::Class::Domain::name, avg 12µs/call # spent 8µs making 3 calls to Foo::Domain::domain_name, avg 3µs/call # spent 7µs making 2 calls to Foo::Child::domain_name, avg 3µs/call # spent 6µs making 2 calls to Foo::Parent::domain_name, avg 3µs/call
59 |  |  |  |  | },
60 | 1 | 6µs | 1 | 1.35ms | ); # spent 1.35ms making 1 call to Moose::has
61 |  |  |  |  |
62 | 1 | 2µs | 1 | 3.12ms | with 'SimpleDB::Class::Role::Itemized'; # spent 3.12ms making 1 call to Moose::with
63 |  |  |  |  |
64 |  |  |  |  | #--------------------------------------------------------
65 |  |  |  |  |
66 |  |  |  |  | =head2 name ( )
67 |  |  |  |  |
68 |  |  |  |  | Returns the name determined automatically by the item_class passed into the constructor.
69 |  |  |  |  |
70 |  |  |  |  | =cut
71 |  |  |  |  |
72 | 1 | 2µs | 1 | 1.22ms | has name => ( # spent 1.22ms making 1 call to Moose::has
73 |  |  |  |  | is => 'rw',
74 |  |  |  |  | isa => 'Str',
75 |  |  |  |  | default => undef,
76 |  |  |  |  | );
77 |  |  |  |  |
78 |  |  |  |  | #--------------------------------------------------------
79 |  |  |  |  |
80 |  |  |  |  | =head2 simpledb ( )
81 |  |  |  |  |
82 |  |  |  |  | Returns the L<SimpleDB::Class> object set in the constructor.
83 |  |  |  |  |
84 |  |  |  |  | =cut
85 |  |  |  |  |
86 | 1 | 2µs | 1 | 955µs | has simpledb => ( # spent 955µs making 1 call to Moose::has
87 |  |  |  |  | is => 'ro',
88 |  |  |  |  | required => 1,
89 |  |  |  |  | );
90 |  |  |  |  |
91 |  |  |  |  | #--------------------------------------------------------
92 |  |  |  |  |
93 |  |  |  |  | =head2 create ( )
94 |  |  |  |  |
95 |  |  |  |  | Creates this domain in the SimpleDB.
96 |  |  |  |  |
97 |  |  |  |  | =cut
98 |  |  |  |  |
99 |  |  |  |  | # spent 4.05s (88µs+4.05) within SimpleDB::Class::Domain::create which was called 3 times, avg 1.35s/call: # once (35µs+1.55s) by main::RUNTIME at line 25 of 05.Domain_and_Item.t # once (27µs+1.25s) by main::RUNTIME at line 77 of 05.Domain_and_Item.t # once (26µs+1.25s) by main::RUNTIME at line 36 of 05.Domain_and_Item.t sub create {
100 | 9 | 77µs |  |  | my ($self) = @_;
101 |  |  |  |  | my $db = $self->simpledb; # spent 9µs making 3 calls to SimpleDB::Class::Domain::simpledb, avg 3µs/call
102 |  |  |  |  | $db->http->send_request('CreateDomain', { # spent 4.04s making 3 calls to SimpleDB::Client::send_request, avg 1.35s/call # spent 8.46ms making 3 calls to SimpleDB::Class::http, avg 2.82ms/call # spent 34µs making 3 calls to SimpleDB::Class::add_domain_prefix, avg 11µs/call # spent 9µs making 3 calls to SimpleDB::Class::Domain::name, avg 3µs/call
103 |  |  |  |  | DomainName => $db->add_domain_prefix($self->name),
104 |  |  |  |  | });
105 |  |  |  |  | }
106 |  |  |  |  |
107 |  |  |  |  | #--------------------------------------------------------
108 |  |  |  |  |
109 |  |  |  |  | =head2 delete ( )
110 |  |  |  |  |
111 |  |  |  |  | Deletes this domain from the SimpleDB.
112 |  |  |  |  |
113 |  |  |  |  | =cut
114 |  |  |  |  |
115 |  |  |  |  | # spent 5.58s (100µs+5.58) within SimpleDB::Class::Domain::delete which was called 3 times, avg 1.86s/call: # once (33µs+3.34s) by main::RUNTIME at line 144 of 05.Domain_and_Item.t # once (36µs+1.13s) by main::RUNTIME at line 143 of 05.Domain_and_Item.t # once (31µs+1.12s) by main::RUNTIME at line 145 of 05.Domain_and_Item.t sub delete {
116 | 9 | 85µs |  |  | my ($self) = @_;
117 |  |  |  |  | my $db = $self->simpledb; # spent 13µs making 3 calls to SimpleDB::Class::Domain::simpledb, avg 4µs/call
118 |  |  |  |  | $db->http->send_request('DeleteDomain', { # spent 5.58s making 3 calls to SimpleDB::Client::send_request, avg 1.86s/call # spent 38µs making 3 calls to SimpleDB::Class::add_domain_prefix, avg 13µs/call # spent 21µs making 3 calls to SimpleDB::Class::http, avg 7µs/call # spent 15µs making 3 calls to SimpleDB::Class::Domain::name, avg 5µs/call
119 |  |  |  |  | DomainName => $db->add_domain_prefix($self->name),
120 |  |  |  |  | });
121 |  |  |  |  | }
122 |  |  |  |  |
123 |  |  |  |  | #--------------------------------------------------------
124 |  |  |  |  |
125 |  |  |  |  | =head2 find ( id, [ options ] )
126 |  |  |  |  |
127 |  |  |  |  | Retrieves an item from the SimpleDB by ID and then returns a L<SimpleDB::Class::Item> object.
128 |  |  |  |  |
129 |  |  |  |  | =head3 id
130 |  |  |  |  |
131 |  |  |  |  | The unique identifier (called ItemName in AWS documentation) of the item to retrieve.
132 |  |  |  |  |
133 |  |  |  |  | =head3 options
134 |  |  |  |  |
135 |  |  |  |  | A hash which allows options to modify the retrieval.
136 |  |  |  |  |
137 |  |  |  |  | =head4 consistent
138 |  |  |  |  |
139 |  |  |  |  | A boolean that if set true will get around Eventual Consistency, but at a reduced performance. Note that since L<SimpleDB::Class> fetches requests by id (like this one) directly from memcached, this option should never be needed. It is provided only for completeness.
140 |  |  |  |  |
141 |  |  |  |  | =head4 set
142 |  |  |  |  |
143 |  |  |  |  | A hash reference of attribute names paired with values that should be set as soon as the item is instantiated. This is useful for prefilling cache attributes, and is used by the C<belongs_to> method for that purpose. Doing so prevents stale object references.
144 |  |  |  |  |
145 |  |  |  |  | =cut
146 |  |  |  |  |
147 |  |  |  |  | # spent 248ms (524µs+248) within SimpleDB::Class::Domain::find which was called 6 times, avg 41.4ms/call: # once (149µs+138ms) by main::RUNTIME at line 106 of 05.Domain_and_Item.t # once (132µs+96.4ms) by main::RUNTIME at line 129 of 05.Domain_and_Item.t # once (93µs+4.72ms) by main::RUNTIME at line 39 of 05.Domain_and_Item.t # once (75µs+4.32ms) by main::RUNTIME at line 83 of 05.Domain_and_Item.t # once (35µs+2.86ms) by main::RUNTIME at line 88 of 05.Domain_and_Item.t # once (39µs+1.10ms) by SimpleDB::Class::Item::__ANON__[../lib/SimpleDB/Class/Item.pm:280] at line 279 of ../lib/SimpleDB/Class/Item.pm sub find {
148 | 89 | 439µs |  |  | my ($self, $id, %options) = @_;
149 |  |  |  |  | SimpleDB::Class::Exception::InvalidParam->throw(name=>'id', value=>undef) unless defined $id;
150 |  |  |  |  | my $db = $self->simpledb; # spent 22µs making 6 calls to SimpleDB::Class::Domain::simpledb, avg 4µs/call
151 |  |  |  |  | my $cache = $db->cache; # spent 25µs making 6 calls to SimpleDB::Class::cache, avg 4µs/call
152 |  |  |  |  | my $name = $db->add_domain_prefix($self->name); # spent 69µs making 6 calls to SimpleDB::Class::add_domain_prefix, avg 12µs/call # spent 24µs making 6 calls to SimpleDB::Class::Domain::name, avg 4µs/call
153 |  |  |  |  |
154 |  |  |  |  | # instantiate item
155 |  |  |  |  | my $attributes = eval{$cache->get($name, $id)}; # spent 6.90ms making 6 calls to SimpleDB::Class::Cache::get, avg 1.15ms/call
156 |  |  |  |  | my $e;
157 |  |  |  |  | my $item;
158 | 1 | 1µs | 16 | 7.89ms | if (SimpleDB::Class::Exception::ObjectNotFound->caught) { # spent 7.74ms making 4 calls to SimpleDB::Class::Role::Itemized::instantiate_item, avg 1.94ms/call # spent 143µs making 10 calls to Exception::Class::Base::caught, avg 14µs/call # spent 6µs making 2 calls to Exception::Class::Base::__ANON__[Exception/Class/Base.pm:30], avg 3µs/call
159 |  |  |  |  | my %params = (
160 |  |  |  |  | ItemName => $id,
161 |  |  |  |  | DomainName => $name,
162 |  |  |  |  | );
163 |  |  |  |  | if ($options{consistent}) {
164 |  |  |  |  | $params{ConsistentRead} = 'true';
165 |  |  |  |  | }
166 |  |  |  |  | my $result = $db->http->send_request('GetAttributes', \%params); # spent 202ms making 2 calls to SimpleDB::Client::send_request, avg 101ms/call # spent 13µs making 2 calls to SimpleDB::Class::http, avg 6µs/call
167 |  |  |  |  | $item = $self->parse_item($id, $result->{GetAttributesResult}{Attribute}); # spent 29.7ms making 2 calls to SimpleDB::Class::Role::Itemized::parse_item, avg 14.8ms/call
168 |  |  |  |  | if (defined $item) { # spent 770µs making 2 calls to SimpleDB::Class::Cache::set, avg 385µs/call # spent 210µs making 2 calls to SimpleDB::Class::Item::to_hashref, avg 105µs/call
169 |  |  |  |  | $cache->set($name, $id, $item->to_hashref);
170 |  |  |  |  | }
171 |  |  |  |  | }
172 |  |  |  |  | elsif (my $e = SimpleDB::Class::Exception->caught) {
173 |  |  |  |  | warn $e->error;
174 |  |  |  |  | $e->rethrow;
175 |  |  |  |  | }
176 |  |  |  |  | elsif (defined $attributes) {
177 |  |  |  |  | $item = $self->instantiate_item($attributes, $id);
178 |  |  |  |  | }
179 |  |  |  |  | else {
180 |  |  |  |  | SimpleDB::Class::Exception->throw(error=>"An undefined error occured while fetching the item.");
181 |  |  |  |  | }
182 |  |  |  |  |
183 |  |  |  |  | # process the 'set' option
184 |  |  |  |  | return undef unless defined $item;
185 |  |  |  |  | foreach my $attribute (keys %{$options{set}}) {
186 |  |  |  |  | $item->$attribute( $options{set}{$attribute} ); # spent 6µs making 1 call to Foo::Domain::parent
187 |  |  |  |  | }
188 |  |  |  |  |
189 |  |  |  |  | return $item;
190 |  |  |  |  | }
191 |  |  |  |  |
192 |  |  |  |  | #--------------------------------------------------------
193 |  |  |  |  |
194 |  |  |  |  | =head2 insert ( attributes, [ options ] )
195 |  |  |  |  |
196 |  |  |  |  | Adds a new item to this domain.
197 |  |  |  |  |
198 |  |  |  |  | =head3 attributes
199 |  |  |  |  |
200 |  |  |  |  | A hash reference of name value pairs to insert as attributes into this item.
201 |  |  |  |  |
202 |  |  |  |  | =head3 options
203 |  |  |  |  |
204 |  |  |  |  | A hash of extra options to modify the put.
205 |  |  |  |  |
206 |  |  |  |  | =head4 id
207 |  |  |  |  |
208 |  |  |  |  | Optionally specify a unqiue id for this item.
209 |  |  |  |  |
210 |  |  |  |  | =head4 set
211 |  |  |  |  |
212 |  |  |  |  | A hash reference of attribute names paired with values that should be set as soon as the item is instantiated. This is useful for prefilling cache attributes to prevent stale object references.
213 |  |  |  |  |
214 |  |  |  |  | =cut
215 |  |  |  |  |
216 |  |  |  |  | # spent 3.88s (359µs+3.88) within SimpleDB::Class::Domain::insert which was called 11 times, avg 353ms/call: # once (25µs+1.32s) by main::RUNTIME at line 126 of 05.Domain_and_Item.t # once (31µs+492ms) by main::RUNTIME at line 33 of 05.Domain_and_Item.t # once (27µs+340ms) by main::RUNTIME at line 38 of 05.Domain_and_Item.t # once (25µs+337ms) by main::RUNTIME at line 104 of 05.Domain_and_Item.t # once (61µs+319ms) by main::RUNTIME at line 44 of 05.Domain_and_Item.t # once (24µs+318ms) by main::RUNTIME at line 41 of 05.Domain_and_Item.t # once (29µs+293ms) by main::RUNTIME at line 32 of 05.Domain_and_Item.t # once (30µs+132ms) by main::RUNTIME at line 78 of 05.Domain_and_Item.t # once (50µs+122ms) by main::RUNTIME at line 45 of 05.Domain_and_Item.t # once (27µs+116ms) by main::RUNTIME at line 37 of 05.Domain_and_Item.t # once (29µs+87.8ms) by main::RUNTIME at line 80 of 05.Domain_and_Item.t sub insert {
217 | 44 | 287µs |  |  | my ($self, $attributes, %options) = @_;
218 |  |  |  |  | my $item = $self->instantiate_item($attributes, $options{id})->put; # spent 3.86s making 11 calls to SimpleDB::Class::Item::put, avg 351ms/call # spent 16.6ms making 11 calls to SimpleDB::Class::Role::Itemized::instantiate_item, avg 1.51ms/call
219 |  |  |  |  |
220 |  |  |  |  | # process 'set' option
221 |  |  |  |  | foreach my $attribute (keys %{$options{set}}) {
222 |  |  |  |  | $item->$attribute( $options{set}{$attribute} );
223 |  |  |  |  | }
224 |  |  |  |  |
225 |  |  |  |  | return $item;
226 |  |  |  |  | }
227 |  |  |  |  |
228 |  |  |  |  | #--------------------------------------------------------
229 |  |  |  |  |
230 |  |  |  |  | =head2 count ( [ options ] )
231 |  |  |  |  |
232 |  |  |  |  | Returns an integer indicating how many items are in this domain.
233 |  |  |  |  |
234 |  |  |  |  | WARNING: With this method you need to be aware that SimpleDB is eventually consistent. See L<SimpleDB::Class/"Eventual Consistency"> for details.
235 |  |  |  |  |
236 |  |  |  |  | =head3 options
237 |  |  |  |  |
238 |  |  |  |  | A hash containing options to modify the count.
239 |  |  |  |  |
240 |  |  |  |  | =head4 where
241 |  |  |  |  |
242 |  |  |  |  | A where clause as defined in L<SimpleDB::Class::SQL> if you want to count only a certain number of items in the domain.
243 |  |  |  |  |
244 |  |  |  |  | =head4 consistent
245 |  |  |  |  |
246 |  |  |  |  | A boolean that if set true will get around Eventual Consistency, but at a reduced performance.
247 |  |  |  |  |
248 |  |  |  |  | =cut
249 |  |  |  |  |
250 |  |  |  |  | # spent 140ms (135µs+140) within SimpleDB::Class::Domain::count which was called 2 times, avg 70.1ms/call: # once (76µs+76.6ms) by main::RUNTIME at line 31 of 05.Domain_and_Item.t # once (60µs+63.5ms) by main::RUNTIME at line 34 of 05.Domain_and_Item.t sub count {
251 | 12 | 112µs |  |  | my ($self, %options) = @_;
252 |  |  |  |  | my $select = SimpleDB::Class::SQL->new( # spent 93µs making 2 calls to SimpleDB::Class::SQL::new, avg 47µs/call # spent 11µs making 2 calls to SimpleDB::Class::Domain::item_class, avg 5µs/call # spent 9µs making 2 calls to SimpleDB::Class::Domain::simpledb, avg 5µs/call
253 |  |  |  |  | item_class => $self->item_class,
254 |  |  |  |  | simpledb => $self->simpledb,
255 |  |  |  |  | where => $options{where},
256 |  |  |  |  | output => 'count(*)',
257 |  |  |  |  | );
258 |  |  |  |  | my %params = ( SelectExpression => $select->to_sql ); # spent 308µs making 2 calls to SimpleDB::Class::SQL::to_sql, avg 154µs/call
259 |  |  |  |  | if ($options{consistent}) {
260 |  |  |  |  | $params{ConsistentRead} = 'true';
261 |  |  |  |  | }
262 |  |  |  |  | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 140ms making 2 calls to SimpleDB::Client::send_request, avg 69.8ms/call # spent 11µs making 2 calls to SimpleDB::Class::http, avg 6µs/call # spent 4µs making 2 calls to SimpleDB::Class::Domain::simpledb, avg 2µs/call
263 |  |  |  |  | return $result->{SelectResult}{Item}[0]{Attribute}{Value};
264 |  |  |  |  | }
265 |  |  |  |  |
266 |  |  |  |  | #--------------------------------------------------------
267 |  |  |  |  |
268 |  |  |  |  | =head2 fetch_ids ( [ options ] )
269 |  |  |  |  |
270 |  |  |  |  | Returns an array reference of ids (itemName()s) in the domain.
271 |  |  |  |  |
272 |  |  |  |  | WARNING: With this method you need to be aware that SimpleDB is eventually consistent. See L<SimpleDB::Class/"Eventual Consistency"> for details.
273 |  |  |  |  |
274 |  |  |  |  | =head3 options
275 |  |  |  |  |
276 |  |  |  |  | A hash containing options to modify the array reference.
277 |  |  |  |  |
278 |  |  |  |  | =head4 where
279 |  |  |  |  |
280 |  |  |  |  | A where clause as defined in L<SimpleDB::Class::SQL> if you want to fetch only a certain number of items in the domain.
281 |  |  |  |  |
282 |  |  |  |  | =head4 consistent
283 |  |  |  |  |
284 |  |  |  |  | Defaults to 0. A boolean that if set true will get around Eventual Consistency, but at a reduced performance.
285 |  |  |  |  |
286 |  |  |  |  | =cut
287 |  |  |  |  |
288 |  |  |  |  | # spent 53.1ms (85µs+53.0) within SimpleDB::Class::Domain::fetch_ids which was called # once (85µs+53.0ms) by main::RUNTIME at line 139 of 05.Domain_and_Item.t sub fetch_ids {
289 | 12 | 66µs |  |  | my ($self, %options) = @_;
290 |  |  |  |  | my $select = SimpleDB::Class::SQL->new( # spent 44µs making 1 call to SimpleDB::Class::SQL::new # spent 5µs making 1 call to SimpleDB::Class::Domain::item_class # spent 5µs making 1 call to SimpleDB::Class::Domain::simpledb
291 |  |  |  |  | item_class => $self->item_class,
292 |  |  |  |  | simpledb => $self->simpledb,
293 |  |  |  |  | where => $options{where},
294 |  |  |  |  | output => 'itemName()',
295 |  |  |  |  | );
296 |  |  |  |  | my %params = ( SelectExpression => $select->to_sql ); # spent 353µs making 1 call to SimpleDB::Class::SQL::to_sql
297 |  |  |  |  | if ($options{consistent}) {
298 |  |  |  |  | $params{ConsistentRead} = 'true';
299 |  |  |  |  | }
300 |  |  |  |  | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 52.6ms 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::Domain::simpledb
301 |  |  |  |  | my $items = $result->{SelectResult}{Item};
302 |  |  |  |  | my @ids;
303 |  |  |  |  | foreach my $item (@{$items}) {
304 |  |  |  |  | push @ids, $item->{Name};
305 |  |  |  |  | }
306 |  |  |  |  | return \@ids;
307 |  |  |  |  | }
308 |  |  |  |  |
309 |  |  |  |  | #--------------------------------------------------------
310 |  |  |  |  |
311 |  |  |  |  | =head2 max ( attribute, [ options ] )
312 |  |  |  |  |
313 |  |  |  |  | Returns the maximum value of an attribute.
314 |  |  |  |  |
315 |  |  |  |  | WARNING: With this method you need to be aware that SimpleDB is eventually consistent. See L<SimpleDB::Class/"Eventual Consistency"> for details.
316 |  |  |  |  |
317 |  |  |  |  | =head3 attribute
318 |  |  |  |  |
319 |  |  |  |  | The name of the attribute to find the maximum value of.
320 |  |  |  |  |
321 |  |  |  |  | =head3 options
322 |  |  |  |  |
323 |  |  |  |  | A hash of options to modify the search.
324 |  |  |  |  |
325 |  |  |  |  | =head4 where
326 |  |  |  |  |
327 |  |  |  |  | A where clause as defined by L<SimpleDB::Class::SQL>. An optional clause to limit the range of the maximum value.
328 |  |  |  |  |
329 |  |  |  |  | =head4 consistent
330 |  |  |  |  |
331 |  |  |  |  | A boolean that if set true will get around Eventual Consistency, but at a reduced performance.
332 |  |  |  |  |
333 |  |  |  |  | =cut
334 |  |  |  |  |
335 |  |  |  |  | # spent 157ms (183µs+157) within SimpleDB::Class::Domain::max which was called 2 times, avg 78.4ms/call: # once (104µs+85.1ms) by main::RUNTIME at line 46 of 05.Domain_and_Item.t # once (79µs+71.5ms) by main::RUNTIME at line 48 of 05.Domain_and_Item.t sub max {
336 | 18 | 150µs |  |  | my ($self, $attribute, %options) = @_;
337 |  |  |  |  | my $where = {
338 |  |  |  |  | $attribute => ['!=','-1000001'],
339 |  |  |  |  | };
340 |  |  |  |  | if (ref $options{where} eq 'HASH') {
341 |  |  |  |  | $where->{'-and'} = $options{where};
342 |  |  |  |  | }
343 |  |  |  |  | my $select = SimpleDB::Class::SQL->new( # spent 103µs making 2 calls to SimpleDB::Class::SQL::new, avg 52µs/call # spent 10µs making 2 calls to SimpleDB::Class::Domain::simpledb, avg 5µs/call # spent 7µs making 2 calls to SimpleDB::Class::Domain::item_class, avg 4µs/call
344 |  |  |  |  | simpledb => $self->simpledb,
345 |  |  |  |  | item_class => $self->item_class,
346 |  |  |  |  | where => $where,
347 |  |  |  |  | limit => 1,
348 |  |  |  |  | order_by => [$attribute],
349 |  |  |  |  | output => $attribute,
350 |  |  |  |  | );
351 |  |  |  |  | my %params = ( SelectExpression => $select->to_sql ); # spent 1.39ms making 2 calls to SimpleDB::Class::SQL::to_sql, avg 697µs/call
352 |  |  |  |  | if ($options{consistent}) {
353 |  |  |  |  | $params{ConsistentRead} = 'true';
354 |  |  |  |  | }
355 |  |  |  |  | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 144ms making 2 calls to SimpleDB::Client::send_request, avg 72.2ms/call # spent 11µs making 2 calls to SimpleDB::Class::http, avg 5µs/call # spent 4µs making 2 calls to SimpleDB::Class::Domain::simpledb, avg 2µs/call
356 |  |  |  |  | my $value = $result->{SelectResult}{Item}[0]{Attribute}{Value};
357 |  |  |  |  | return $self->item_class->parse_value($attribute, $value); # spent 10.8ms making 2 calls to SimpleDB::Class::Item::parse_value, avg 5.39ms/call # spent 10µs making 2 calls to SimpleDB::Class::Domain::item_class, avg 5µs/call
358 |  |  |  |  | }
359 |  |  |  |  |
360 |  |  |  |  | #--------------------------------------------------------
361 |  |  |  |  |
362 |  |  |  |  | =head2 min ( attribute, [ options ] )
363 |  |  |  |  |
364 |  |  |  |  | Returns the minimum value of an attribute.
365 |  |  |  |  |
366 |  |  |  |  | WARNING: With this method you need to be aware that SimpleDB is eventually consistent. See L<SimpleDB::Class/"Eventual Consistency"> for details.
367 |  |  |  |  |
368 |  |  |  |  | =head3 attribute
369 |  |  |  |  |
370 |  |  |  |  | The name of the attribute to find the minimum value of.
371 |  |  |  |  |
372 |  |  |  |  | =head3 options
373 |  |  |  |  |
374 |  |  |  |  | A hash of extra options to modify the search.
375 |  |  |  |  |
376 |  |  |  |  | =head4 where
377 |  |  |  |  |
378 |  |  |  |  | A where clause as defined by L<SimpleDB::Class::SQL>. An optional clause to limit the range of the minimum value.
379 |  |  |  |  |
380 |  |  |  |  | =head4 consistent
381 |  |  |  |  |
382 |  |  |  |  | A boolean that if set true will get around Eventual Consistency, but at a reduced performance.
383 |  |  |  |  |
384 |  |  |  |  | =cut
385 |  |  |  |  |
386 |  |  |  |  | # spent 129ms (138µs+129) within SimpleDB::Class::Domain::min which was called 2 times, avg 64.6ms/call: # once (75µs+72.1ms) by main::RUNTIME at line 47 of 05.Domain_and_Item.t # once (64µs+56.9ms) by main::RUNTIME at line 49 of 05.Domain_and_Item.t sub min {
387 | 18 | 118µs |  |  | my ($self, $attribute, %options) = @_;
388 |  |  |  |  | my $where = {
389 |  |  |  |  | $attribute => ['!=','-1000001'],
390 |  |  |  |  | };
391 |  |  |  |  | if (ref $options{where} eq 'HASH') {
392 |  |  |  |  | $where->{'-and'} = $options{where};
393 |  |  |  |  | }
394 |  |  |  |  | my $select = SimpleDB::Class::SQL->new( # spent 82µs making 2 calls to SimpleDB::Class::SQL::new, avg 41µs/call # spent 8µs making 2 calls to SimpleDB::Class::Domain::simpledb, avg 4µs/call # spent 5µs making 2 calls to SimpleDB::Class::Domain::item_class, avg 3µs/call
395 |  |  |  |  | simpledb => $self->simpledb,
396 |  |  |  |  | item_class => $self->item_class,
397 |  |  |  |  | where => $where,
398 |  |  |  |  | limit => 1,
399 |  |  |  |  | order_by => $attribute,
400 |  |  |  |  | output => $attribute,
401 |  |  |  |  | );
402 |  |  |  |  | my %params = ( SelectExpression => $select->to_sql ); # spent 1.19ms making 2 calls to SimpleDB::Class::SQL::to_sql, avg 593µs/call
403 |  |  |  |  | if ($options{consistent}) {
404 |  |  |  |  | $params{ConsistentRead} = 'true';
405 |  |  |  |  | }
406 |  |  |  |  | my $result = $self->simpledb->http->send_request('Select', \%params); # spent 127ms making 2 calls to SimpleDB::Client::send_request, avg 63.6ms/call # spent 10µs making 2 calls to SimpleDB::Class::http, avg 5µs/call # spent 3µs making 2 calls to SimpleDB::Class::Domain::simpledb, avg 2µs/call
407 |  |  |  |  | my $value = $result->{SelectResult}{Item}[0]{Attribute}{Value};
408 |  |  |  |  | return $self->item_class->parse_value($attribute, $value); # spent 455µs making 2 calls to SimpleDB::Class::Item::parse_value, avg 227µs/call # spent 9µs making 2 calls to SimpleDB::Class::Domain::item_class, avg 5µs/call
409 |  |  |  |  | }
410 |  |  |  |  |
411 |  |  |  |  | #--------------------------------------------------------
412 |  |  |  |  |
413 |  |  |  |  | =head2 search ( options )
414 |  |  |  |  |
415 |  |  |  |  | Returns a L<SimpleDB::Class::ResultSet> object.
416 |  |  |  |  |
417 |  |  |  |  | WARNING: With this method you need to be aware that SimpleDB is eventually consistent. See L<SimpleDB::Class/"Eventual Consistency"> for details.
418 |  |  |  |  |
419 |  |  |  |  | =head3 options
420 |  |  |  |  |
421 |  |  |  |  | A hash of options to set up the search.
422 |  |  |  |  |
423 |  |  |  |  | =head4 where
424 |  |  |  |  |
425 |  |  |  |  | A where clause as defined by L<SimpleDB::Class::SQL>.
426 |  |  |  |  |
427 |  |  |  |  | =head4 order_by
428 |  |  |  |  |
429 |  |  |  |  | An order by clause as defined by L<SimpleDB::Class::SQL>.
430 |  |  |  |  |
431 |  |  |  |  | =head4 limit
432 |  |  |  |  |
433 |  |  |  |  | A limit clause as defined by L<SimpleDB::Class::SQL>.
434 |  |  |  |  |
435 |  |  |  |  | =head4 consistent
436 |  |  |  |  |
437 |  |  |  |  | A boolean that if set true will get around Eventual Consistency, but at a reduced performance.
438 |  |  |  |  |
439 |  |  |  |  | =head4 set
440 |  |  |  |  |
441 |  |  |  |  | A hash reference of attribute names paired with values that should be set as soon as the item is instantiated. This is useful for prefilling cache attributes as items come off the result set, and is used by the C<has_many> method for that purpose. Doing so prevents stale object references.
442 |  |  |  |  |
443 |  |  |  |  | =cut
444 |  |  |  |  |
445 |  |  |  |  | # spent 1.71ms (234µs+1.47) within SimpleDB::Class::Domain::search which was called 10 times, avg 171µs/call: # 3 times (55µs+370µs) by Foo::Domain::children or Foo::Parent::domains at line 207 of ../lib/SimpleDB/Class/Item.pm, avg 142µs/call # once (39µs+171µs) by main::RUNTIME at line 51 of 05.Domain_and_Item.t # once (32µs+177µs) by main::RUNTIME at line 118 of 05.Domain_and_Item.t # once (22µs+171µs) by main::RUNTIME at line 61 of 05.Domain_and_Item.t # once (23µs+166µs) by main::RUNTIME at line 68 of 05.Domain_and_Item.t # once (20µs+144µs) by main::RUNTIME at line 132 of 05.Domain_and_Item.t # once (21µs+137µs) by main::RUNTIME at line 70 of 05.Domain_and_Item.t # once (21µs+136µs) by main::RUNTIME at line 58 of 05.Domain_and_Item.t sub search {
446 | 40 | 202µs |  |  | my ($self, %options) = @_;
447 |  |  |  |  | $options{simpledb} = $self->simpledb; # spent 35µs making 10 calls to SimpleDB::Class::Domain::simpledb, avg 4µs/call
448 |  |  |  |  | $options{item_class} = $self->item_class; # spent 33µs making 10 calls to SimpleDB::Class::Domain::item_class, avg 3µs/call
449 |  |  |  |  | return SimpleDB::Class::ResultSet->new(%options); # spent 1.41ms making 10 calls to SimpleDB::Class::ResultSet::new, avg 141µs/call
450 |  |  |  |  | }
451 |  |  |  |  |
452 |  |  |  |  | =head1 LEGAL
453 |  |  |  |  |
454 |  |  |  |  | SimpleDB::Class is Copyright 2009-2010 Plain Black Corporation (L<http://www.plainblack.com/>) and is licensed under the same terms as Perl itself.
455 |  |  |  |  |
456 |  |  |  |  | =cut
457 |  |  |  |  |
458 | 3 | 60µs | 2 | 248µs | # spent 129µs (10+119) within SimpleDB::Class::Domain::BEGIN@458 which was called # once (10µs+119µs) by SimpleDB::Class::BEGIN@141 at line 458 no Moose; # spent 129µs making 1 call to SimpleDB::Class::Domain::BEGIN@458 # spent 119µs making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:478]
459 | 1 | 46µs | 2 | 2.52ms | __PACKAGE__->meta->make_immutable; # spent 2.50ms making 1 call to Class::MOP::Class::make_immutable # spent 17µs making 1 call to SimpleDB::Class::Domain::meta