clear-code / redmine_full_text_search

Full text search for Redmine
MIT License
61 stars 24 forks source link

Add support for destroying a custom field #109

Closed HashidaTKS closed 1 year ago

HashidaTKS commented 1 year ago

GitHub: fix GH-108

If a searchable CustomField is destroyed, corresponding FullTextSearch::Target records are also destroyed. We can't use existing mapper mechanism for it because CustomField uses has_many :custom_values, :dependent => :delete_all relation. It doesn't call after_destroy callback that is needed to synchronize CustomFieldValue and FullTextSearch::Target.

We can remove orphaned FullTextSearch::Target for destroyed CustomFieldValue by bin/rails full_text_search:synchronize.

kou commented 1 year ago

We should remove entries that refer nonexistent Redmine records instead of not touching them on search.

HashidaTKS commented 1 year ago

Thanks! I will try to fix current changes to remove entries that refer nonexistent records.

HashidaTKS commented 1 year ago

Concern: This changes don't remove already left fts records. (The error is not resolved only apply this changes, already left fts records should be removed.)

HashidaTKS commented 1 year ago

Concern: This changes don't remove already left fts records. (The error is not resolved only apply this changes, already left fts records should be removed.)

When we should remove the already left (orphan) fts records? I thinks 2. is better.

  1. When migration
  2. When startup Redmine
  3. When removing a field, which means that removing not only fts records using the field, but also orphan fts records not using the field.
HashidaTKS commented 1 year ago

@kou

Would you review this when you have time? Do you have any good idea for https://github.com/clear-code/redmine_full_text_search/pull/109#issuecomment-1410062309 ?

kou commented 1 year ago

bin/rails full_text_search:synchronize removes orphan FullTextSearch::Target.