Problem/Motivation
When a user clicks a link to subscribe to a forum taxonomy term, the label of the link is not updated correctly to display "Unsubscribe" until a page reload. And in some cases, a page reload does not even resolve the issue.
I noticed in the browser console I got an error message "User already subscribed\\/unsubscribed.". I also checked the DB and, in effect, the user was already subscribed to the forum but since the action of the link did not change to unsubscribe, the link is still pointing to the subscribe endpoint. This causes the error shown in the console.
I tried debugging the code and I noticed that the operations are cached in the Content Plugin of the Content submodule so the operations links to subscribe and unsubscribe are not updated correctly. Apparently, the change made here causes this issue https://www.drupal.org/project/danse/issues/3350871. The code that is causing the issue for me is in this function https://git.drupalcode.org/project/danse/-/commit/ea608668c414b78b2cc09565f5a1db16ccfb013c#46213d5ceb28331ceb6fbc0a9d40b66b17c95cbe_203_214.
Steps to reproduce
- Configure the module to display operations to subscribe to new published forum topics.
- Subscribe to a forum, and check if the label changes.
- In case the label changes, unsubscribe and subscribe again until it is not changing anymore.
Proposed resolution
Not sure if there is a way to disable this caching feature in sites with a small number of bundles.
Or an alternative is to cache only the array of the operation and calculate every time the action (Subscribe/ Unsubscribe) on the function subscriptionOperations.
Comments
Comment #2
aroy-iqvia commentedThat's right, In the latest version, there's no way the user can unsubscribe after subscribing. Unless we clear the system cache. I had to revert to version 2.2.13 to fix the label.
Comment #3
walkero commentedI am experiencing the same problem with v2.3. I just started setting up this module, and it seems not to work properly because of this issue. I wonder if it is recommended to get back to the older version (2.2) and if there will be an update path in the future.
Comment #4
rex.barkdoll commentedI'm adding in as well. I'm getting a 403 Ajax error whenever trying to unsubscribe.
Javascript in browser console:
dblog error:
Comment #6
jurgenhaasYour observation was absolutely right @s_castro that the caching was the reason for this broken behaviour. That was introduced in #3350871: Huge performance issue on sites with a lot of entity types and bundles and increased the performance a lot. However, it cached the widget operations per entity type and entity id, but forgot about the user. These widgets are individual for each entity per user, so the user ID needs to go into the cache ID as well.
That alone didn't fix it yet. We also need to reset the cache for an entity if the subscription status for that entity changes for a specific user.
Both parts have been fixed and it seems to be working correctly now. Please give it a try.
Comment #7
rex.barkdoll commentedUpgrading to the current dev version fixed my issue and seems to be working well.
Comment #8
jurgenhaasThanks for testing.