소스 검색

[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 년 전
부모
커밋
1ed28bf3a2
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  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