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 Array | |
def no_duplicates? | |
tally.values.all? {|v| v == 1 } | |
end | |
end | |
class Card | |
attr_reader :picture, :suit | |
def initialize(picture, suit) |
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
# German rails_admin translation | |
de: | |
admin: | |
home: | |
name: "Home" | |
pagination: | |
previous: "« Vor" | |
next: "Zurück »" | |
truncate: "…" |
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 AddOrderedDealershipIdExpiredAtIndexToLeaseDeals < ActiveRecord::Migration[5.2] | |
def change | |
remove_index :lease_deals, name: :index_lease_deals_on_dealership_id_and_expired_at, algorithm: :concurrently | |
add_index :lease_deals, %i[id dealership_id expired_at], where: 'expired_at IS NULL', using: :btree, order: { id: :asc }, algorithm: :concurrently | |
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
class LeaseDeal < ApplicationRecord | |
def self.expire_all(time: Time.current, batch_size: 1000) | |
ids = pluck(:id) | |
ids.each_slice(batch_size) do |ids_slice| | |
unscoped.where(id: ids_slice).update_all(expired_at: time) | |
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
# Snippets taken from: | |
# https://github.com/rails/rails/blob/fc5dd0b85189811062c85520fd70de8389b55aeb/activerecord/lib/active_record/relation/batches.rb#L201 | |
def in_batches(of: 1000, start: nil, finish: nil, load: false, error_on_ignore: nil) | |
relation = self | |
# ... | |
batch_limit = of | |
# ... | |
relation = relation.reorder(batch_order).limit(batch_limit) | |
relation = apply_limits(relation, start, finish) |
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
Limit (cost=0.11..4232.55 rows=1000 width=4) | |
-> Index Scan using lease_deals_pkey on lease_deals (cost=0.11..3130311.24 rows=739600 width=4) | |
Filter: ((expired_at IS NULL) AND (updated_at < '2018-10-09 09:26:33.507679'::timestamp without time zone) AND (dealership_id = 5678)) |
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
Bitmap Heap Scan on lease_deals (cost=448.02..903.13 rows=5903 width=205) | |
Recheck Cond: ((dealership_id = 1234) AND (expired_at IS NULL)) | |
Filter: ((updated_at < '2018-10-09 09:34:11.818701'::timestamp without time zone)) | |
-> Bitmap Index Scan on index_lease_deals_on_dealership_id_and_expired_at (cost=0.00..411.04 rows=6724 width=0) | |
Index Cond: (dealership_id = 1234) |
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 AddPartialIndexOnDealershipIdAndExpiredAtToLeaseDeals < ActiveRecord::Migration[5.2] | |
def change | |
add_index :lease_deals, %i[dealership_id expired_at], where: 'expired_at IS NULL', algorithm: :concurrently | |
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
Bitmap Heap Scan on lease_deals (cost=172.99..18520.04 rows=5903 width=205) | |
Recheck Cond: (dealership_id = 1234) | |
Filter: ((expired_at IS NULL) AND (updated_at < '2018-10-09 09:34:11.818701'::timestamp without time zone)) | |
-> Bitmap Index Scan on index_lease_deals_on_dealership_id (cost=0.00..172.70 rows=9724 width=0) | |
Index Cond: (dealership_id = 1234) |
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
SELECT "lease_deals"."id" | |
FROM "lease_deals" | |
WHERE "lease_deals"."expired_at" IS NULL | |
AND "lease_deals"."dealership_id" = 1234 | |
AND ( updated_at < '2018-10-09 09:34:11.818701' ) | |
ORDER BY "lease_deals"."id" ASC | |
LIMIT 1000 |
NewerOlder