From 5f2fbf4f0665daa196dda2e058eb0f37e3dfc052 Mon Sep 17 00:00:00 2001 From: nixx Date: Fri, 24 Jan 2025 11:42:11 +0300 Subject: [PATCH] request with synchronize, update testing workflow --- .github/workflows/testing.yml | 12 +++++++----- README.md | 6 +++++- .../clickhouse/schema_statements.rb | 10 ++++++---- lib/clickhouse-activerecord/version.rb | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 4e71fab..f372ce3 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -30,13 +30,13 @@ jobs: rails: 7.2.1 - ruby: 3.2 rails: 8.0.1 - clickhouse: [ '22.1', '24.6' ] + clickhouse: [ '22.1', '24.9' ] steps: - uses: actions/checkout@v4 - name: Start ClickHouse ${{ matrix.clickhouse }} - uses: isbang/compose-action@v1.5.1 + uses: hoverkraft-tech/compose-action@v2.1.0 env: CLICKHOUSE_VERSION: ${{ matrix.clickhouse }} with: @@ -74,14 +74,16 @@ jobs: - ruby: 3.2 rails: 7.1.3 - ruby: 3.2 - rails: 7.2.0 - clickhouse: [ '22.1', '24.6' ] + rails: 7.2.1 + - ruby: 3.2 + rails: 8.0.1 + clickhouse: [ '22.1', '24.9' ] steps: - uses: actions/checkout@v4 - name: Start ClickHouse Cluster ${{ matrix.clickhouse }} - uses: isbang/compose-action@v1.5.1 + uses: hoverkraft-tech/compose-action@v2.1.0 env: CLICKHOUSE_VERSION: ${{ matrix.clickhouse }} with: diff --git a/README.md b/README.md index d10a531..b5b21a1 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,11 @@ Action.settings(optimize_read_in_order: 1).where(date: Date.current).limit(10) User.joins(:actions).using(:group_id) # Clickhouse User Load (10.3ms) SELECT users.* FROM users INNER JOIN actions USING group_id -#=> #]> +#=> #]> + +User.window('x', order: 'date', partition: 'name', rows: 'UNBOUNDED PRECEDING').select('sum(value) OVER x') +# SELECT sum(value) OVER x FROM users WINDOW x AS (PARTITION BY name ORDER BY date ROWS UNBOUNDED PRECEDING) +#=> #]> ``` diff --git a/lib/active_record/connection_adapters/clickhouse/schema_statements.rb b/lib/active_record/connection_adapters/clickhouse/schema_statements.rb index 9dfe973..03a1988 100644 --- a/lib/active_record/connection_adapters/clickhouse/schema_statements.rb +++ b/lib/active_record/connection_adapters/clickhouse/schema_statements.rb @@ -178,10 +178,12 @@ def with_yaml_fallback(value) # :nodoc: def request(sql, format = nil, settings = {}) formatted_sql = apply_format(sql, format) request_params = @connection_config || {} - @connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, { - 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}", - 'Content-Type' => 'application/x-www-form-urlencoded', - }) + @lock.synchronize do + @connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, { + 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}", + 'Content-Type' => 'application/x-www-form-urlencoded', + }) + end end def apply_format(sql, format) diff --git a/lib/clickhouse-activerecord/version.rb b/lib/clickhouse-activerecord/version.rb index 4b9e83f..8d3ab85 100644 --- a/lib/clickhouse-activerecord/version.rb +++ b/lib/clickhouse-activerecord/version.rb @@ -1,3 +1,3 @@ module ClickhouseActiverecord - VERSION = '1.2.1' + VERSION = '1.3.0' end