acts_as_follower
acts_as_follower copied to clipboard
are the `fk_follows` and `fk_followables` indexes needed?
i am going through my codebase and cleaning up extraneous indexes and wondered if the fk_follows and fk_followables indexes are needed? i ask because the migration already creates two indexes
- index_follows_on_followable_type_and_followable_id
- index_follows_on_follower_type_and_follower_id
as defined implicitly by these polymorphic references:
class ActsAsFollowerMigration < ActiveRecord::Migration
def self.up
create_table :follows, force: true do |t|
t.references :followable, polymorphic: true, null: false
t.references :follower, polymorphic: true, null: false
...
end
end
...
end
so are these two additional indexes required?
class ActsAsFollowerMigration < ActiveRecord::Migration
def self.up
create_table :follows, force: true do |t|
...
end
add_index :follows, ["follower_id", "follower_type"], name: "fk_follows"
add_index :follows, ["followable_id", "followable_type"], name: "fk_followables"
end
...
end
the main difference is the order of the index elements:
-
[:follower_type, :follower_id]rather than[:follower_id, :follower_type] -
[:followable_type, :followable_id]rather than[:followable_id, :followable_type]
if these two defined indexes are indeed required, then are the implicitly created ones needed? not a huge deal, but i'd thought i'd ask since i couldn't find an answer elsewhere. thanks!