- For diffing terms, we only need to store terms for the current comment and the previous one
- We don't need the logic of #314260: Strange behavior when comment_alter_taxonomy module is enabled after node is already created anymore
- We don't need to store terms if they haven't changed anymore (should save space!)
But
- There is a potential concurrency issue if two comments are created on the same issue at nearly the same time (moderately critical, because it can occur in a very short time frame, and because the collision should be harmless).
Comments
Comment #1
aclight commentedI'll try to look at the patch this weekend.
I just glanced at the patch thus far. If two comments were to be created at nearly the same time, what happens? Just a few extra rows get written to the database but otherwise functionality is fine?
Any chance that the master/slave configuration used on d.o would cause problems with this method?
Comment #2
aclight commentedComment #3
aclight commentedThe patch in the original issue has the same problem that #314260: Strange behavior when comment_alter_taxonomy module is enabled after node is already created fixed. However, the attached patch fixes the problem by adding an additional check in comment_alter_taxonomy_project_issue_metadata(). Otherwise the patch is the same.
Comment #4
aclight commentedPatch in #3 doesn't work in the case where a node without any terms is created before the module is enabled and, after enabling the module, a comment is added that changes the terms. In this situation the addition of the term is not displayed in the comment the term was added.
Comment #5
damien tournoud commented- we remove the tid = 0 dummy term if there are term saved.
- we check that there are really terms loaded before doing the diff.
Comment #6
aclight commentedSame patch but with a few modifications to the comment in _comment_alter_taxonomy_build_term_list().
Comment #7
aclight commentedUpdated phpdoc for return value in _comment_alter_taxonomy_build_term_list().
Comment #8
aclight commentedIn the case where the only record in {cat} for a comment is the row where tid=0, the db query above still returns nothing, because we're joining on {term_data}, which should never have a row with tid=0.
So, if a node has been created but has no comments, when the module is enabled and a new comment is created on the node, with terms added, the addition of terms on that node is not displayed in the diff table.
Comment #9
aclight commentedOk, I think this finally works properly in all cases.
Comment #10
webchickOn the concurrency issue, I spoke with killes and he said that he didn't think this was particularly a big deal. The worst we're going to get is "Duplicate ID '34353' for query.."
But I wonder if we could remove the window for concurrency-related problems entirely (or at least make it MUCH smaller) by doing a subquery here?
INSERT INTO ... SELECT FROM ...
Comment #11
damien tournoud commentedHere is an implementation of webchick suggestion.
Untested for now.
Comment #12
damien tournoud commentedAnd actually saved the buffer before publishing the patch (the count logic was not updated).
Comment #13
killes@www.drop.org commentedimproved patch to simplify the "tid = 0" case.
Comment #14
damien tournoud commentedWe insert tid = 0 first to reduce the possible window of exposure of the concurrency issue. Plus IGNORE is only supported on MySQL, so the following patch makes it a special case.
Comment #15
damien tournoud commentedAnd remove a parse error.
Comment #16
killes@www.drop.org commentedThis is now live on scratch and seems to work. There is one bug in the diff logic: if the module was enabled after the node was created, there is no entry in the cta table and the diff function returns FALSE. THis leads to the diff not being displayed for the first comment adding terms. it should return an empty array.
Comment #17
damien tournoud commentedWe always save both the terms of the previous comment as well as the terms of the current comment. So the behavior you are describing should not happen.
Comment #18
damien tournoud commentedThere was a logical error in the previous patch on the removal of the dummy term. This should solve it.
Comment #19
damien tournoud commentedAfter some more testing on scratch.drupal.org, I committed this to HEAD.