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
class ApplicationRecord < ActiveRecord::Base | |
... | |
after_create_commit do | |
ActiveRecord::Base.connection.execute("CLUSTER #{self.class.table_name}") | |
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
-- DO NOT RUN IN PRODUCTION | |
-- Supported on PSQL 9.6+. | |
-- Note: If all your tables aren’t located in the public schema | |
-- be sure to modify the specified schemaname | |
do $$ | |
declare | |
selectrow record; | |
begin | |
for selectrow in | |
select |
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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
# Activate the gem you are reporting the issue against. |
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
@posts = Post.all | |
@posts = @posts.where(published: true) unless current_admin | |
@posts = @posts.where(author: selected_author) unless any_author? | |
@posts = @posts.search_by_title(search_param).default_order |
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
@posts = Post.search_by_title(search_param).default_order | |
@posts = @posts.select do |post| | |
(post.author == selected_author || any_author?) && (post.published? || current_admin) | |
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
NUMBER_OF_TRIALS = 100 | |
NUM_OF_CHARS = 43 | |
CHAR_LIST = ('a'..'z').to_a | |
SEARCH_TERMS = CHAR_LIST.map do |letter| | |
letter + '?' * (NUM_OF_CHARS - 1) | |
end | |
results = Hash.new { |h, k| h[k] = [] } | |
NUMBER_OF_TRIALS.times do |i| |
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
NUMBER_OF_TRIALS = 100 | |
DIGIT_LENGTH_RANGE = (10..70) | |
SEARCH_TERMS = DIGIT_LENGTH_RANGE.map do |i| | |
'?' * i | |
end | |
results = Hash.new { |h, k| h[k] = [] } | |
NUMBER_OF_TRIALS.times do |i| | |
SEARCH_TERMS.each do |term| |
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
NUMBER_OF_TRIALS = 100 | |
SEARCH_TERMS = ['scott', 'blake'] | |
results = Hash.new { |h, k| h[k] = [] } | |
NUMBER_OF_TRIALS.times do |i| | |
SEARCH_TERMS.each do |term| | |
results[term] << benchmark_get(term) | |
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
require 'benchmark' | |
def benchmark_get(search_term) | |
bm = Benchmark.realtime do | |
get(search_term) | |
end | |
bm * 1000 | |
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
require 'httparty' | |
URL = 'http://localhost:3000/posts?search=' | |
def get(search_term) | |
HTTParty.get("#{URL}#{search_term}") | |
end |
NewerOlder