Database Reference
In-Depth Information
Stating attributes using the :select option
Design your tests table with a compound primary key. The
:hash_value
function will
be a UUID of the user and the
:range_value
will be the timestamp, which will be the
start time of the test. For such tables in DynamoDB, you can use the query API to query the
test items. It will consume some options and the
:hash_value
function will be required.
You can either specify different kinds of range values or use the
:limit
option to filter
down the tests that you want to retrieve from the table.
In your initial implementation, you can do something similar to what is given in the follow-
ing code:
uchittests = items.query(
:hash_value => "user UUID",
:scan_index_forward => false,
:limit => 10)
uchittests.each do |test|
render test.attributes.to_h
end
The previous code will salvage the last 10 tests run by a user. It will offer the necessary res-
ults, but it is unexpectedly slow in my case. The
aws-sdkgems
function will lazy load
the attributes for each item by default. So, here you can call
test.attributes.to_h
,
which will trigger a new request to DynamoDB to retrieve each attribute. In all it will make
1 + 10 * num_attributes
requests to retrieve your data!
To resolve this you can use the
:select
option to state the attributes you require:
uchittests = items.query(
:hash_value => "user UUID",
:scan_index_forward => false,
:limit => 10,
:select => ['timestamp', 'url', 'response_time'])
uchittests.each do |test|
render test.attributes['timestamp'],
test.attributes['url'],