Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ REDIS_RESULT_TTL_DAYS=1
ROUTER_API_KEY=demo
ROUTER_URL=http://localhost:8082/0.1
SENTRY_DSN=
PUMA_WORKERS=4
PUMA_THREADS=0:1
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gem 'grape-swagger-entity'
gem 'actionpack', require: 'action_dispatch'
# waiting for the following PRs to get merged and "released!"
# https://github.com/zilkey/active_hash/pull/231 and https://github.com/zilkey/active_hash/pull/233
gem 'active_hash', github: 'cartoway/active_hash', branch: 'dev'
gem 'active_hash'
gem 'activemodel'
gem 'activesupport', require: 'active_support'
gem 'google-protobuf', '>=3', require: 'google/protobuf'
Expand Down
18 changes: 6 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
GIT
remote: https://github.com/cartoway/active_hash.git
revision: 10a84f020aada46febc91cf2f0fddcbd3a5485eb
branch: dev
specs:
active_hash (3.1.0)
activesupport (>= 5.0.0)

GIT
remote: https://github.com/cartoway/rubocop-policy.git
revision: 209bde9a8088d4204b22829b2a9150860c16dcac
Expand Down Expand Up @@ -41,6 +33,8 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_hash (4.0.0)
activesupport (>= 6.1.0)
activemodel (7.0.8)
activesupport (= 7.0.8)
activesupport (7.0.8)
Expand All @@ -64,7 +58,7 @@ GEM
charlock_holmes (0.7.9)
chunky_png (1.4.0)
color-generator (0.0.4)
concurrent-ruby (1.2.2)
concurrent-ruby (1.3.5)
crack (0.4.5)
rexml
crass (1.0.6)
Expand Down Expand Up @@ -118,7 +112,7 @@ GEM
http-cookie (1.0.5)
domain_name (~> 0.5)
http_accept_language (2.1.1)
i18n (1.14.1)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.6)
json (2.7.1)
Expand All @@ -133,7 +127,7 @@ GEM
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0808)
minitest (5.20.0)
minitest (5.26.0)
minitest-around (0.5.0)
minitest (~> 5.0)
minitest-bisect (1.7.0)
Expand Down Expand Up @@ -303,7 +297,7 @@ PLATFORMS

DEPENDENCIES
actionpack
active_hash!
active_hash
activemodel
activesupport
ai4r
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
<<: *default-service
ports:
- "8083:80" # HOST:CONTAINER, edit only HOST part
command: bundle exec puma -v -p 80 --pidfile 'server.pid'
command: bundle exec puma -v -p 80 --pidfile 'server.pid' -t ${PUMA_THREADS:-0:1}" -w ${PUMA_WORKERS:-4}"
restart: unless-stopped

resque-default:
Expand Down
21 changes: 21 additions & 0 deletions models/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ def initialize(hash)
end

class << self
# Override active_hash to improve performances
def insert(record)
@records ||= []
record_id(record)
validate_unique_id(record) if dirty
mark_dirty

add_to_record_index({ record.id.to_s => @records.length })
@records << record
end

# Override active_hash to improve performances
def record_id(record)
# sets record[:id] to @max_id+1 if it doesn't exist
if record[:id]&.is_a?(Numeric)
@max_id = [@max_id || 0, record[:id].ceil].max
else
record[:id] ||= (@max_id = @max_id.to_i.succ)
end
end

def json_fields
@json_fields ||= []
end
Expand Down
Loading