-
-
Notifications
You must be signed in to change notification settings - Fork 71
Remove special case notifying author of threads #1037
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
Remove special case notifying author of threads #1037
Conversation
Instead of special casing creating a notification, we just have them follow normally automatically.
|
By the way (I forgot to mention), this does mean that everyone will no longer be following new threads on their posts since this change isn't retroactive. They'd have to actually click the follow new threads button on their posts. Someone could presumably make a one-off migration script somewhere to fix this, I'm not confident enough to do so myself. |
Oh, that would be bad; we don't want to quietly cancel notifications on older posts. I don't know how to write the migration script either, but the other way to do it would be to keep the extra check until we do -- so do make the change where we implement notifications as auto-follows on new posts, but in the code that decides whether to notify, keep the check for "is my post" along with "is followed" until we can fix existing follows. |
Problems discovered during testingI also don't know how to write the database script, but happy to work together on learning how once we know what we're aiming for. Before that, I've found some odd behaviour. I've tested on this new branch and also on I checked the contents of the Summary of the problems
Tests on
|
|
Sorry it took so long to address those issues! Life (and accidental database corruption) got in the way. The last commit should fix them (apparently there comment following logic is spread out over all three of Test 1
Test 3
Test 2
Test 4
|
|
Thanks for fixing all the problems! Please don't apologise for life getting in the way - life comes first. I'm not just saying that because of being distracted myself recently - it's my view in general. I don't have access to approve pull requests but it's looking good to me. Is the database script you mentioned previously the only thing remaining now? I'm guessing it would need to do the following:
It looks like there are some one-off scripts in |
|
We could set this up on the dev server for testing when the DB-update stuff is ready. |
|
@MoshiKoi So users need to follow their own posts now, that would be Then modify this file and change the change method as follows: def change
to_insert = Post.where.not(post_type_id: [PolicyDoc.post_type_id, HelpDoc.post_type_id])
.where.not(user_id: nil)
.pluck(:id, :user_id)
.map { |post_id, user_id| { post_id: post_id, user_id: user_id } }
ThreadFollower.insert_all(to_insert)
endThis will transform each post into an entry SELECT id, user_id FROM posts WHERE post_type_id IN (?, ?) AND user_id IS NOT NULL;
INSERT INTO thread_followers (post_id, user_id, created_at, updated_at) VALUES (?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()), (?, ?, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()), ...In rails, it avoids constructing all the post objects, instead constructing only an array of the ids and user ids, which is then transformed into an array of hashes to be able to be passed to insert_all. |
|
I'm looking at this pull request because it affects comment threads, which are also going to be changed by #767. This makes me want to get this pull request merged first in order to fix the bugs addressed by this pull request before changing how comment threads work. My understanding
@cellio the migration will make every post author a follower of every one of their own posts. This initially sounds like it will destroy information (an author who had unfollowed one of their own posts would now be made a follower again). However, in testing the
@cellio yes, once this pull request is merged, your own future posts will default to following all new threads. In summary:
Can we test this on the dev server?I believe this branch is ready to be tested on the dev server. Can this be done without deleting the existing dev server database so that the migration can be tested on the existing data? The database migration script currently only exists in @Taeir 's comment, so it would need to be generated following the instructions in that comment before this could be tested on the dev server. I'm happy to generate it myself but will wait for any replies before proceeding. Technically data corruptionI'm not concerned about this personally, but I'd like to describe what I expect to happen in case anyone objects to this, or believes the outcome will be different than I expect.
The reason that some posts may already have one or more rows in the thread_followers table is that pressing "Follow new" under your post will add a row to this table (even though currently the bug prevents it having any effect). Currently, pressing "Unfollow new" will only remove one row from the table, even if several exist. This pull request fixes this, so pressing "Follow new" or "Unfollow new" in future will result in exactly 1 row or exactly 0 rows, respectively. I am not aware of any negative effect of having these duplicate rows (which likely already exist in the live database due to the bug). Before merging this pull request they are ignored, and after merging this pull request they will have the intended effect even when duplicated, and will have the duplication fixed if ever the post author presses "Unfollow new". Testing the duplicate rowsWe could test that there is no negative effect by pressing "Follow new" or "Unfollow new" on a few posts on the dev server before the database migration script is run. Removing the duplicate rowsAlternatively, we could add a step to the migration before inserting the new rows. This could remove all existing rows for which the user who is following a post is also the post author, so that we start with zero rows for every post for its post author, and end up with no duplication and no way for future duplication to be introduced. The reason I'm not pushing for this is that I expect the total number of existing rows to be very small (they should only exist where the post author has pressed the "Follow new" or "Unfollow new" buttons). I'm not proposing an approach where we only add new rows if none exist already, as that would not solve the problem of existing rows that are already duplicates (more than 1 exists already). |
|
@trichoplax , that all sounds good to me. I don't feel qualified to sign off on the "technically data corruption" section -- sounds fine to me and I'm twitchy about data deletion, but I don't know if this duplication causes any issues -- and defer to @ArtOfCode- . One additional thing for the migration script: do we need to do anything special to account for deleted post authors? Deleted users still exist in the |
At present, the migration script is including deleted posts but excluding posts for which the user is nil. I don't know why a post would have its user set to nil, or whether any such posts exist at present. My only guess is that this might correspond to destroyed (rather than just deleted) users. For deleted (rather than destroyed) users, your thinking sounds reasonable to me (having a follower row for a deleted user shouldn't break anything, and we'd want the row to be present if ever we undeleted the user). If anyone is aware of a problem that would be caused by a deleted user being a follower of their own post, then this will likely also be a problem for the code (not just the migration script), since every user that is deleted in future will already be a follower of all of their own posts (if this pull request has been merged by that point). |
Deleted posts, or posts whose users are deleted? Migrating posts with deleted (but non-nil) authors sounds like the right thing to me. I think users who are actually destroyed are nil, and we definitely have some of those in prod (and other instances might), so we want to exclude those. While we're removing "destroy" from the UI in the mod-tools branch, we might still occasionally need to do that (directly in the DB) to comply with data-privacy laws, so our code should assume that it can happen. |
Good catch - I meant posts whose users are deleted. That sentence should have said:
|
7d89490
into
codidact:MoshiKoi/1025/remove-special-case-notifying-author-of-threads
Instead of special casing creating a notification, we just have them follow normally automatically. Resolves #1025