Skip to content

Commit

Permalink
Add Order and LIMIT to get_products query
Browse files Browse the repository at this point in the history
  • Loading branch information
huoxito committed Oct 27, 2014
1 parent 13bccb5 commit 3ed80bb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/SF_services/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def latest_updates(time = Time.now.utc.iso8601)
since = time ? Time.parse(time).utc.iso8601 : Time.now.utc.iso8601

fields = "Id, Name, ProductCode, Description, LastModifiedDate"
products = salesforce.query("select #{fields} from Product2 where LastModifiedDate > #{since}")
filter = "LastModifiedDate > #{since} ORDER BY LastModifiedDate ASC LIMIT 100"
salesforce.query("select #{fields} from Product2 where #{filter}")
end

def find_prices_by_product_ids(product_ids)
Expand Down
2 changes: 1 addition & 1 deletion lib/integrations/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def latest_products
end

def latest_timestamp_update(products = nil)
if product = (products || latest_products).sort_by { |p| p["LastModifiedDate"] }.last
if product = (products || latest_products).to_a.last
Time.parse(product["LastModifiedDate"]).utc.iso8601
else
Time.now.utc.iso8601
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/integrations/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
it "grabs last timestamp and return in iso8601" do
products = [
{ "LastModifiedDate" => "2014-09-21 T21:44:32.000+0000" },
{ "LastModifiedDate" => "2014-10-21 T21:44:32.000+0000" },
{ "LastModifiedDate" => "2014-10-21 T01:43:32.000+0000" },
{ "LastModifiedDate" => "2014-10-21 T01:44:32.000+0000" },
{ "LastModifiedDate" => "2014-10-21 T21:43:32.000+0000" },
]

expect(subject.latest_timestamp_update products).to eq "2014-10-21T21:44:32Z"
expect(subject.latest_timestamp_update products).to eq "2014-10-21T21:43:32Z"
expect(subject.latest_timestamp_update []).to be_present
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/salesforce_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

it "empty get products result" do
payload = {
parameters: config.merge(salesforce_products_since: "2014-10-24T19:14:57-03:00")
parameters: config.merge(salesforce_products_since: "2014-10-28T19:14:57-03:00")
}

VCR.use_cassette "requests/get_products_empty" do
Expand Down

0 comments on commit 3ed80bb

Please sign in to comment.