There are some duplicated tags due to database corruption and I can't merge

AI-generated summary

The discussion revolves around database corruption causing duplicate tags in a Discourse forum. Pad_Pors initially reported the issue and provided images illustrating the problem. pfaffman suggested it might be due to a corrupt index and shared a link to a similar issue.

neil believed the issue was likely caused by a corrupt index or a bad third-party plugin, but Pad_Pors had already removed the duplicates manually, which resulted in inaccessible tag pages. neil advised updating the topics using the affected tags via the command line.

Pad_Pors asked for a command to find corrupted and duplicated tags, and pfaffman shared a link to a similar issue he had encountered. RGJ suggested the index corruption might be related to the Farsi language settings, which Pad_Pors suspected could be due to differences in alphabets and encoding.

as can be seen in the image, in our forums there are some tags that are exactly the same!

when creating a topic, you will see different number of topics in these tags:

but if you choose one, both will be chosen. but then as you click on the tags, both direct you to the same page with similar topics and topic numbers. so admins can’t merge them or delete one of them.

this is a sample topic in our forum with 2 sets of duplicated tags.

I had a similar problem that was due to an index being corrupt.

I don’t know if this will help Can't restore due to corrupt indexes (with some clues on how to deal with corrupt indexes)

@neil any ideas here, is this a side effect of synonyms?

Unlikely, we’ve seen a lot of corrupt indexes and bad third party plugins cause this.

Sounds the same as this topic:

There’s a unique index on the tag name column, so it shouldn’t be possible to have duplicate tags. I’m guessing if you did reindex table tags it would fail.

@pfaffman’s process here is probably what you’ll need to do to remove the duplicate tags and fix the indexes.

this is the list of plugins we have, I guess none of them may be related to tags:

I already removed them by hand! or let’s say, I could remove one of the duplicates for each pair; and then the page for the other tag in the pair became in-accessible (even for admins)! as we go to the page, we get “that page doesn’t exist or is private”, though there are several topics with that tag.

an example would be tag یادگیری which should have 488 topics in it, while the tag-page doesn’t exist (link to the tag page):

image

p.s.: sorry the pages and the tags are non-English. I hope it gives a clue.

It sounds like you did it from the UI, but it can’t be done that way. As Jay did, you need to update all topics that use one of the tags to use the other, like in his example:

TopicTag.where(tag_id: 717).update_all(tag_id: 611)

thanks, are there any command to find the corrupted tags (those I have already changed from UI) as well as the duplicated tags? if so, may you guide me?

I describe how I did it (or something similar) over at Can't restore due to corrupt indexes (with some clues on how to deal with corrupt indexes) - #14 by pfaffman. It’s far from a howto, but might help. You have to switch back and forth between the rails console and psql, which if you’re not familiar with both might be confusing or intimidating. If it doesn’t and you have a budget, I’ve done it recently. :wink:

I don’t think the index corruption is caused by a plugin.
I’ve seen this kind of PSQL index corruption five times in the past few months and four of them were using Farsi language settings.

I also think this is a Contribute > Bug, and the bad part is that it’s ongoing! no matter I have deleted previous duplicates, I get new ones again. if it helps I can remove the non-official plugins and check the birth of new duplicates.

if it was due to Farsi language, I’d suggest it may be because of some of apparently similar but basically different alphabets that different keyboards are using. for example some devices use Arabic alphabet and some use Persian. and in these keyboards we have ي and ی, which when used in a word one can’t distinguish among them (but they are different in encoding).

but @Pfaffman 's case was for English indexes, bot Persian!

Yes, that is the (sole) not-Farsi one I know of.