Skip to content

Commit

Permalink
Revert "ActiveForce .first performance enhancement (#73)" (#76)
Browse files Browse the repository at this point in the history
* Revert "ActiveForce .first performance enhancement (#73)"

This reverts commit 8fbd5bd.

* 0.20.1 release stuff.
  • Loading branch information
asedge authored Nov 29, 2023
1 parent 1272b67 commit ecb9115
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 30 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ spec/reports
test/tmp
test/version_tmp
tmp
.idea
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Not released

## 0.20.1
- Revert "ActiveForce .first performance enhancement (#73)" (https://github.com/Beyond-Finance/active_force/pull/76)

## 0.20.0

- Change `.first` to not query the API if records have already been retrieved (https://github.com/Beyond-Finance/active_force/pull/73)
Expand Down
16 changes: 4 additions & 12 deletions lib/active_force/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,7 @@ def find id
end

def first
if @records
clone_and_set_instance_variables(
size: 1,
records: [@records.first],
decorated_records: [@decorated_records&.first]
)
else
limit(1)
end
limit 1
end

def last(limit = 1)
Expand Down Expand Up @@ -134,9 +126,9 @@ def build_offset

def clone_and_set_instance_variables instance_variable_hash={}
clone = self.clone
{ decorated_records: nil, records: nil }
.merge(instance_variable_hash)
.each { |k,v| clone.instance_variable_set("@#{k.to_s}", v) }
clone.instance_variable_set(:@decorated_records, nil)
clone.instance_variable_set(:@records, nil)
instance_variable_hash.each { |k,v| clone.instance_variable_set("@#{k.to_s}", v) }
clone
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_force/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ActiveForce
VERSION = '0.20.0'
VERSION = '0.20.1'
end
16 changes: 0 additions & 16 deletions spec/active_force/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,6 @@
expect(query.to_s).to eq "SELECT Id, name, etc FROM table_name"
expect(new_query.to_s).to eq 'SELECT Id, name, etc FROM table_name LIMIT 1'
end

it "does not query if records have already been fetched" do
query = ActiveForce::Query.new 'table_name'
query.instance_variable_set(:@records, %w[foo bar])
query.instance_variable_set(:@decorated_records, %w[foo bar])
expect(query).not_to receive(:limit)
expect(query).to receive(:clone_and_set_instance_variables).with(size: 1, records: ['foo'], decorated_records: ['foo'])
query.first
end

it 'queries the api if it has not been queried yet' do
query = ActiveForce::Query.new 'table_name'
query.instance_variable_set(:@records, nil)
expect(query).to receive(:limit)
query.first
end
end

describe '.last' do
Expand Down

0 comments on commit ecb9115

Please sign in to comment.