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
# Improve indexing to remove records whose sphinx document id is stale due to changes to the number/order of indices | |
module SphinxIndexing | |
# Delete existing record before inserting new ones. This avoids the need to rebuild the index after adding or removing | |
# an index. Without this, the old indexed record would not be deleted since Sphinx's calculation of that record's id | |
# would not match now that the number/order of indices has changed. | |
module Transcriber | |
def copy(*instances) | |
return unless instances.present? | |
ids = instances.map(&:id).compact |
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
module OuterJoins | |
def outer_joins(*associations) | |
pattern = / (?:INNER )?JOIN /i | |
scope = all | |
associations.each do |association| | |
inner_join_sql = scope.unscoped.joins(association).to_sql | |
outer_join_sql = inner_join_sql.gsub(pattern, ' LEFT OUTER JOIN ') | |
scope = scope.joins(outer_join_sql[/LEFT OUTER JOIN .+/]) | |
end |
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
begin | |
class CreateModels < ActiveRecord::Migration | |
def change | |
create_table :items do |t| | |
end | |
create_table :events do |t| | |
t.belongs_to :item | |
end |
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 DatabaseController < ApplicationController | |
def database_dump | |
database = Rails.configuration.database_configuration[Rails.env]["database"] | |
send_file_headers!(:type => 'application/octet-stream', :filename => "#{database}_#{Time.now.to_s(:human)}.backup") | |
pipe = IO.popen("pg_dump '#{database}' -F c") | |
stream = response.stream | |
while (line = pipe.gets) | |
stream.write line | |
sleep 0.0001 # HACK: Prevent server instance from sleeping forever if client disconnects during download |
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
require 'active_record' | |
require 'logger' | |
# Print out what version we're running | |
puts "Active Record #{ActiveRecord::VERSION::STRING}" | |
# Connect to an in-memory sqlite3 database (more on this in a moment) | |
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') | |
# Create the minimal database schema necessary to reproduce the bug |
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
require 'active_record' | |
require 'logger' | |
# Print out what version we're running | |
puts "Active Record #{ActiveRecord::VERSION::STRING}" | |
# Connect to an in-memory sqlite3 database (more on this in a moment) | |
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') | |
# Create the minimal database schema necessary to reproduce the bug |
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 EntityViewSweeperWorker < Workling::Base | |
# Expires the view fragments for a particular entity based on options[:type] and options[:id] | |
def expire_fragment_for_all(options) | |
expire_fragment(/#{options[:type].tableize}\/#{options[:id]}\/views\//) | |
end | |
end | |