diff --git a/lib/tasks/readyset.rake b/lib/tasks/readyset.rake index 048a16b..29e2e4b 100644 --- a/lib/tasks/readyset.rake +++ b/lib/tasks/readyset.rake @@ -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' diff --git a/spec/rake_spec.rb b/spec/rake_spec.rb index bf6beeb..bfbf99f 100644 --- a/spec/rake_spec.rb +++ b/spec/rake_spec.rb @@ -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