mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 21:09:49 +08:00
FIX: Ensure post_hotlinked_media index does not exceed size limit (#16609)
On some installations, this would fail with 'index row size exceeds btree version 4 maximum'. This commit replaces the (post_id, url)` index with a `(post_id, md5(url))` index, which is much more space efficient.
This commit is contained in:
parent
51e29d3ca8
commit
19d2d55011
|
@ -25,5 +25,5 @@ end
|
|||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_post_hotlinked_media_on_post_id_and_url (post_id,url) UNIQUE
|
||||
# index_post_hotlinked_media_on_post_id_and_url_md5 (post_id, md5((url)::text)) UNIQUE
|
||||
#
|
||||
|
|
|
@ -22,9 +22,15 @@ class CreatePostHotlinkedMedia < ActiveRecord::Migration[6.1]
|
|||
t.bigint :upload_id
|
||||
t.timestamps
|
||||
|
||||
t.index [:post_id, :url], unique: true
|
||||
# Failed on some installations due to index size. Repaired in 20220428094027
|
||||
# t.index [:post_id, :url], unique: true
|
||||
end
|
||||
|
||||
execute <<~SQL
|
||||
CREATE UNIQUE INDEX index_post_hotlinked_media_on_post_id_and_url_md5
|
||||
ON post_hotlinked_media (post_id, md5(url));
|
||||
SQL
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
execute <<~SQL
|
||||
|
|
22
db/migrate/20220428094027_fix_post_hotlinked_media_index.rb
Normal file
22
db/migrate/20220428094027_fix_post_hotlinked_media_index.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class FixPostHotlinkedMediaIndex < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
execute <<~SQL
|
||||
CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS index_post_hotlinked_media_on_post_id_and_url_md5
|
||||
ON post_hotlinked_media (post_id, md5(url));
|
||||
SQL
|
||||
|
||||
# Failed index introduced in 20220428094026_create_post_hotlinked_media. On some installations it succeeded,
|
||||
# so we need to clean it up.
|
||||
execute <<~SQL
|
||||
DROP INDEX CONCURRENTLY IF EXISTS index_post_hotlinked_media_on_post_id_and_url;
|
||||
SQL
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user