Skip to content

feat: support merging tag #1315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

feat: support merging tag #1315

wants to merge 5 commits into from

Conversation

hgaol
Copy link
Member

@hgaol hgaol commented Apr 21, 2025

Close #1110 .

Process when merging one tag to another.

  1. update the main tag id for source tag and its synonyms to target tag
  2. migrate tag followers from source tag to target tag
    1. check if they're both tag.follow action
    2. get all user ids who follow the source tag
    3. transaction
      1. cancel follow source tag. (can changed to delete follow source tag records if needed)
      2. update cancel status to active for target tag if source tag followers is active
      3. get user ids without following target tag, and create new activities to follow target tag for these users.
  3. update question tags
    1. update tag_id to target tag id in tag_rel table when all below conditions met
      1. tag_id equals source tag id
      2. object_id is with question prefix, which is 1001
      3. questions without target tag. Which means questions that already with target tag will be ignored
    2. refresh question count for source tag and target tag

Test cases validated

  1. questions. init state: questions1(t1, t2, t3), question2(t4), question3(t3)
    1. t2 -> t1: t2 becomes synonym of t1, questions1(t1, t2, t3), question2(t4), question3(t3)
    2. t4 -> t1: t4 becomes synonym of t1, questions1(t1, t2, t3), question2(t1), question3(t3)
    3. t3 -> t1: t3 becomes synonym of t1, questions1(t1, t2, t3), question2(t1), question3(t1)
    4. t1 remove t2,t3,t4 as syn: questions1(t1, t2, t3), question2(t1), question3(t1)
  2. followers. init state: t1, t2, t3 and t4 all have no followers
    1. follow t2 and merged to t1: following t1.
    2. unfollow t1 and merge t3 to t1: unfollowing t1.
    3. follow t4 and merge to t1: following t1.
    4. remove t2,3,4 as syn: following t1 and unfollowing t2,3,4

@LinkinStars LinkinStars self-requested a review April 22, 2025 03:20
@LinkinStars LinkinStars self-assigned this Apr 22, 2025
@LinkinStars
Copy link
Member

First of all, thanks for the contribution.

And I found an error.

ERROR	handler/handler.go:53	code: 500, reason: base.database_error, message: , error: Error 1093 (HY000): You can't specify target table 'tag_rel' for update in FROM clause
internal/repo/tag/tag_rel_repo.go:220 github.com/apache/answer/internal/repo/tag.(*tagRelRepo).MigrateTagObjects
internal/service/tag_common/tag_common.go:943 github.com/apache/answer/internal/service/tag_common.(*TagCommonService).MigrateTagQuestions
internal/service/tag/tag_service.go:485 github.com/apache/answer/internal/service/tag.(*TagService).MergeTag
UPDATE `tag_rel` SET `tag_id` = ?, `updated_at` = ? WHERE (tag_id = ?) AND (object_id LIKE ?) AND object_id NOT IN (SELECT object_id FROM tag_rel WHERE tag_id=? AND object_id LIKE ?) [10030000000003699 2025-04-23 11:13:03 10030000000003701 1001% 10030000000003699 1001%] - 1.244208ms
  • I think there is no need to use questionPrefix to handle the question's tag situation separately. Currently, only questions contain tags. If other objects want to have tags in the future, the merge operation should be consistent.
  • I understand that you want to deal with a situation where both source and target tags are included. I think it might be to deal with such a situation separately.

Deleting it may be a good choice. This keeps behaviour consistent. For example

questions. init state: questions1(t1, t2, t3), question2(t2)

  • Your version t2 -> t1: t2 becomes synonym of t1, questions1(t1, t2, t3), question2(t1)
  • I think t2 -> t1: t2 becomes synonym of t1, questions1(t1, t3), question2(t1)

The merged behaviour is the same in question 1 and question 2.

@hgaol
Copy link
Member Author

hgaol commented Apr 23, 2025

Thanks @LinkinStars for these suggestions! Does the error happened on MySQL? I've verified with SQLite. Anyway, I'll validated for both databases.
Another question for follower. Should I use same approach? Like deleting old followers on source tag.

BTW, I'm kind of busy recently, will update based on your suggestions later. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants