-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🥗✨
Journal
: Keyword
s can be merged into one another
- https://github.com/zinc-collective/convene/issues/1713 There's a number of things that can and will go wrong with this code eventually, including (but not limited to) 1. What happens when a `Keyword` has 1000s of entries?! 2. If this happens on-request-thread it will probably be very very slow; but if we do it *off* request-thread; the `Keyword#show` UI will be out-of-date; and we haven't implemented `ActionCable` yet But hey, at least I will have a Heroku-CLI affordance for merging some of the `Keywords` that are synonyms... I'll probably want to build out a WUI as well; but I wanted to get the basic logic written down and tested before I tilted at the WUI.
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Journal | ||
# Merges one {Journal::Keyword} into another and tidies up after. | ||
class Keyword::Merge | ||
# @param from {Journal::Keyword} | ||
# @param into {Journal::Keyword} | ||
def self.call(from:, into:) | ||
into.aliases = into.aliases + from.canonical_with_aliases | ||
Keyword.transaction do | ||
into.save! | ||
from.destroy! | ||
into.entries.find_each do |entry| | ||
entry.extract_keywords | ||
entry.save! | ||
end | ||
end | ||
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