Browse Source

[ruby/rails] Use batch update for /update (#9017)

* [ruby/rails] Update trilogy to 2.8.1 and use ssl for connection

This fixes connection errors:

      /usr/local/bundle/gems/activerecord-7.1.3.1/lib/active_record/connection_adapters/trilogy_adapter.rb:61:in
      `rescue in new_client': trilogy_auth_recv: caching_sha2_password
      requires either TCP with TLS or a unix socket: TRILOGY_UNSUPPORTED
      (ActiveRecord::ConnectionNotEstablished)

* [ruby/rails] Use batch update for /update

Use a single query for updating the world records.
Petrik de Heus 1 year ago
parent
commit
1ed28bf3a2
1 changed files with 2 additions and 2 deletions
  1. 2 2
      frameworks/Ruby/rails/app/controllers/hello_world_controller.rb

+ 2 - 2
frameworks/Ruby/rails/app/controllers/hello_world_controller.rb

@@ -37,9 +37,9 @@ class HelloWorldController < ApplicationController
       world = World.find(id)
       world = World.find(id)
       new_value = random_id
       new_value = random_id
       new_value = random_id until new_value != world.randomNumber
       new_value = random_id until new_value != world.randomNumber
-      world.update_columns(randomNumber: new_value)
-      world
+      { id: id, randomNumber: new_value }
     end
     end
+    World.upsert_all(worlds.sort_by!{_1[:id]})
 
 
     render json: worlds
     render json: worlds
   end
   end