-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
railtie: Add relation extension (#41)
This commit adds two methods to `ActiveRecord::Relation`: - `Relation#create_readyset_cache!`, which creates a new cache based on the query represented by the relation; and - `Relation#drop_cache!`, which drops the cache associated with the query represented by the relation (if one exists) --------- Co-authored-by: Paul Lemus <paullemus@protonmail.com>
- Loading branch information
1 parent
152b0a8
commit 6b0d549
Showing
11 changed files
with
303 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Readyset | ||
module RelationExtension | ||
extend ActiveSupport::Concern | ||
|
||
prepended do | ||
# Creates a new cache on ReadySet for this query. This method is a no-op if a cache for the | ||
# query already exists. | ||
# | ||
# NOTE: If the ActiveRecord query eager loads associations (e.g. via `#includes`), the | ||
# the queries issues to do the eager loading will not have caches created. Those queries must | ||
# have their caches created separately. | ||
# | ||
# @return [void] | ||
def create_readyset_cache! | ||
Readyset.create_cache!(sql: to_sql) | ||
end | ||
|
||
# Drops the cache on ReadySet associated with this query. This method is a no-op if a cache | ||
# for the query already doesn't exist. | ||
# | ||
# NOTE: If the ActiveRecord query eager loads associations (e.g. via `#includes`), the | ||
# the queries issues to do the eager loading will not have caches dropped. Those queries must | ||
# have their caches dropped separately. | ||
# | ||
# @return [void] | ||
def drop_readyset_cache! | ||
Readyset.drop_cache!(sql: to_sql) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class Cat < ActiveRecord::Base; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
ActiveRecord::Schema.define do | ||
# Set up any tables you need to exist for your test suite that don't belong | ||
# in migrations. | ||
create_table(:cats, :force => true) do |t| | ||
t.string :name | ||
t.timestamps | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.