Skip to content

Commit

Permalink
add readyset:proxied_query:supported task
Browse files Browse the repository at this point in the history
  • Loading branch information
ethowitz committed Jan 22, 2024
1 parent f343f28 commit d95715c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/tasks/readyset.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ namespace :readyset do

Readyset.raw_query('DROP ALL PROXIED QUERIES')
end

desc 'Prints a list of all the queries that ReadySet has proxied that can be cached'
task supported: :environment do
Rails.application.eager_load!

rows = Readyset::Query::ProxiedQuery.all.
select { |query| query.supported == :yes }.
map { |q| [q.id, q.text, q.count] }
table = Terminal::Table.new(headings: [:id, :text, :count], rows: rows)

puts table
end
end

desc 'Prints a list of all the cached queries on ReadySet'
Expand Down
26 changes: 26 additions & 0 deletions spec/rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,32 @@
expect(proxied).to be_empty
end
end

describe 'supported' do
it 'prints a table that shows only proxied queries supported by ReadySet' do
build_and_execute_proxied_query(:proxied_query)
build_and_execute_proxied_query(:unsupported_proxied_query)

eventually do
Readyset::Query::ProxiedQuery.all.all? { |query| query.supported != :pending }
end

expected_message = Regexp.new <<~TABLE
\\+--------------------\\+------------------------\\+-------\\+
\\| id \\| text \\| count \\|
\\+--------------------\\+------------------------\\+-------\\+
\\| q_4f3fb9ad8f73bc0c \\| SELECT \\| \\d+[ ]*\\|
\\| \\| "cats"\\."breed" \\| [ ]*\\|
\\| \\| FROM \\| [ ]*\\|
\\| \\| "cats" \\| [ ]*\\|
\\| \\| WHERE \\| [ ]*\\|
\\| \\| \\("cats"\\."name" = \\$1\\) \\| [ ]*\\|
\\+--------------------\\+------------------------\\+-------\\+
TABLE
expect { Rake::Task['readyset:proxied_queries:supported'].execute }.
to output(expected_message).to_stdout
end
end
end

describe 'status' do
Expand Down

0 comments on commit d95715c

Please sign in to comment.