This file contains hidden or 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
| class Funko | |
| # Add these scopes to your model | |
| scope :for_user, ->(user) { where(user: user) } | |
| scope :for_category, ->(category) { joins(:category).where(categories: { name: category }) } | |
| scope :newest, -> { order(created_at: :desc) } | |
| end | |
| def index | |
| category = params[:category] | |
| @funkos = Funko.newest |
This file contains hidden or 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 benchmark assumes we're consistently looking for the last | |
| # item in the array. | |
| # | |
| # If you want to use a random number, use i = rand(1..20) in both | |
| # reports. | |
| require "benchmark" | |
| n = 500_000 | |
| arr = (1..20).map { |i| { id: i } } |
This file contains hidden or 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
| package main | |
| import ( | |
| "context" | |
| "encoding/json" | |
| "fmt" | |
| "io" | |
| "log" | |
| "net/http" | |
| "os" |
OlderNewer