我之前不知道有这个插件——真不错!我没有安装它,但我仍然能够进入数据容器并运行查询。
这真是个好线索!如果我正确理解错误消息的话,我认为问题不在于 theme_fields 表,因为那个表没有 theme_field_id。我没有检查源代码,但我猜测 add_index() 的第一个参数是表名,第二个参数是列名。
基于此,看起来问题出在 javascript_caches 表。
== 20230817174049 EnsureJavascriptCacheIsUniquePerTheme: migrating ===========
-- remove_index(:javascript_caches, :theme_id)
-> 0.0208s
-- add_index(:javascript_caches, :theme_id, {:unique=>true})
-> 0.0079s
-- remove_index(:javascript_caches, :theme_field_id)
-> 0.0026s
-- add_index(:javascript_caches, :theme_field_id, {:unique=>true})
所以我检查了那个表的结构,它有 theme_field_id 列:
discourse=# \d javascript_caches
Table "public.javascript_caches"
Column | Type | Collation | Nullable | Default
----------------+-----------------------------+-----------+----------+-----------------------------------------------
id | bigint | | not null | nextval('javascript_caches_id_seq'::regclass)
theme_field_id | bigint | | |
digest | character varying | | |
content | text | | not null |
created_at | timestamp without time zone | | not null |
updated_at | timestamp without time zone | | not null |
theme_id | bigint | | |
source_map | text | | |
Indexes:
"javascript_caches_pkey" PRIMARY KEY, btree (id)
"index_javascript_caches_on_digest" btree (digest)
"index_javascript_caches_on_theme_field_id" btree (theme_field_id)
"index_javascript_caches_on_theme_id" btree (theme_id)
Check constraints:
"enforce_theme_or_theme_field" CHECK (theme_id IS NOT NULL AND theme_field_id IS NULL OR theme_id IS NULL AND theme_field_id IS NOT NULL)
Foreign-key constraints:
"fk_rails_58f94aecc4" FOREIGN KEY (theme_id) REFERENCES themes(id) ON DELETE CASCADE
"fk_rails_ed33506dbd" FOREIGN KEY (theme_field_id) REFERENCES theme_fields(id) ON DELETE CASCADE
我能够查询那个表(缩短了 content 字段以便我能读懂),并且可以看到重复项。但我不知道这些重复项意味着什么。
discourse=# select id, theme_field_id, digest, substring(content from 1 for 64) as content_64, created_at, updated_at, theme_id, substring(source_map from 1 for 64) as source_64 from javascript_caches where theme_field_id = 3;
id | theme_field_id | digest | content_64 | created_at | updated_at | theme_id | source_64
----+----------------+------------------------------------------+------------------------------------------------------------------+----------------------------+----------------------------+----------+------------------------------------------------------------------
1 | 3 | d0b6ec642d5649064ff0501cadc775a9217b16e0 | "define"in window&&define("discourse/theme-3/initializers/theme- | 2019-02-25 01:26:56.606537 | 2023-08-18 20:47:19.596923 | | {"version":3,"sources":["discourse/initializers/theme-field-3-co
2 | 3 | 7fd74ecf4448afccdbcd9ccde87acddb4ec6f514 | "define"in window&&define("discourse/theme-3/initializers/theme- | 2019-02-25 01:26:58.228209 | 2023-08-18 20:50:41.049209 | | {"version":3,"sources":["discourse/initializers/theme-field-3-co
内容看起来很熟悉,所以我进入了 Customize → Theme → My Theme → Common → Head,做了一个小的修改并保存,我可以看到其中一个条目被更新了,而另一个仍然是旧的……
discourse=# select id, theme_field_id, digest, substring(content from 1 for 64) as content_64, created_at, updated_at, theme_id, substring(source_map from 1 for 64) as source_64 from javascript_caches where theme_field_id = 3;
id | theme_field_id | digest | content_64 | created_at | updated_at | theme_id | source_64
----+----------------+------------------------------------------+------------------------------------------------------------------+----------------------------+----------------------------+----------+------------------------------------------------------------------
2 | 3 | 7fd74ecf4448afccdbcd9ccde87acddb4ec6f514 | "define"in window&&define("discourse/theme-3/initializers/theme- | 2019-02-25 01:26:58.228209 | 2023-08-18 20:50:41.049209 | | {"version":3,"sources":["discourse/initializers/theme-field-3-co
1 | 3 | 7f4132b1f9ced1b90b8f8fc24812cc11e81fea8d | "define"in window&&define("discourse/theme-3/initializers/theme- | 2019-02-25 01:26:56.606537 | 2023-09-13 21:56:56.312263 | | {"version":3,"sources":["discourse/initializers/theme-field-3-co
(2 rows)
同样,我不知道这些重复项意味着什么,是否可以安全地删除“旧的”一个,或者是否有其他方法可以“重建”缓存来清理这些?