Skip to content

Instantly share code, notes, and snippets.

@ej2015
Last active December 20, 2019 04:51
Show Gist options
  • Select an option

  • Save ej2015/07f2959b74eb89740e8ca1a0a4e301b5 to your computer and use it in GitHub Desktop.

Select an option

Save ej2015/07f2959b74eb89740e8ca1a0a4e301b5 to your computer and use it in GitHub Desktop.

Revisions

  1. ej2015 renamed this gist Dec 20, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. ej2015 revised this gist Dec 20, 2019. 1 changed file with 8 additions and 9 deletions.
    17 changes: 8 additions & 9 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,13 @@
    Rails cache SQL calls

    So suppose we have a model Author which has_many Book
    ```
    expect(author.books).to equal author.books
    ```

    expect(author.books).to equal author.books

    If Book has a scope, say by_countries:
    ```
    scope :by_countries, -> c { where(countries: c) if c.present? }
    ```

    scope :by_countries, -> c { where(countries: c) if c.present? }

    scoped queries are not cached:
    ```
    expect(author.books.by_countries(nil)).not_to equal author.books.by_countries(nil)
    ```

    expect(author.books.by_countries(nil)).not_to equal author.books.by_countries(nil)
  3. ej2015 created this gist Dec 20, 2019.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    Rails cache SQL calls

    So suppose we have a model Author which has_many Book
    ```
    expect(author.books).to equal author.books
    ```
    If Book has a scope, say by_countries:
    ```
    scope :by_countries, -> c { where(countries: c) if c.present? }
    ```
    scoped queries are not cached:
    ```
    expect(author.books.by_countries(nil)).not_to equal author.books.by_countries(nil)
    ```