Add missing indexes from #7234#7533
Conversation
| end | ||
| end | ||
|
|
||
| def disconnect_contacts |
There was a problem hiding this comment.
See commit-message: Also remove disconnect_contacts methods, because contacts are already removed with aspects memberships in before_destroy.
I had a problem after changing this to use person instead of diaspora_handle, because it tried to do this twice, but the second time it failed, because contact.user was nil.
There was a problem hiding this comment.
And the tests ensures that contacts are empty after the AccountDeleter run, so that shouldn't be a problem when something changes in the future.
There was a problem hiding this comment.
Actually before_destroy block in AspectMembership doesn't delete contacts if it's sharing: true. So it's not the same thing as disconnect_contacts in AccountDeleter. I have no idea why it worked for you, but it now fails with contacts not empty for me.
Here is my pry session output that shows what happens to a contact actually:
From: /home/senya/source/diaspora/app/models/aspect_membership.rb @ line 14 :
9: has_one :user, :through => :contact
10: has_one :person, :through => :contact
11:
12: before_destroy do
13: binding.pry
=> 14: if self.contact && self.contact.aspects.size == 1
15: self.user.disconnect(self.contact)
16: end
17: true
18: end
19:
[2] pry(#<AspectMembership>)> self.contact.aspects.size
=> 1
[4] pry(#<AspectMembership>)> user.contacts
=> [#<Contact:0x0000000dfeff08
id: 1105,
user_id: 1139,
person_id: 4295,
created_at: Mon, 14 Aug 2017 01:56:40 UTC +00:00,
updated_at: Mon, 14 Aug 2017 01:56:40 UTC +00:00,
sharing: true,
receiving: true>]
[5] pry(#<AspectMembership>)> next
From: /home/senya/source/diaspora/app/models/aspect_membership.rb @ line 15 :
10: has_one :person, :through => :contact
11:
12: before_destroy do
13: binding.pry
14: if self.contact && self.contact.aspects.size == 1
=> 15: self.user.disconnect(self.contact)
16: end
17: true
18: end
19:
20: def as_json(opts={})
[5] pry(#<AspectMembership>)> next
From: /home/senya/source/diaspora/app/models/aspect_membership.rb @ line 17 :
12: before_destroy do
13: binding.pry
14: if self.contact && self.contact.aspects.size == 1
15: self.user.disconnect(self.contact)
16: end
=> 17: true
18: end
19:
20: def as_json(opts={})
21: {
22: :id => self.id,
[6] pry(#<AspectMembership>)> user.contacts.reload
=> [#<Contact:0x0000000f50cfa8
id: 1105,
user_id: 1139,
person_id: 4295,
created_at: Mon, 14 Aug 2017 01:56:40 UTC +00:00,
updated_at: Mon, 14 Aug 2017 01:57:25 UTC +00:00,
sharing: true,
receiving: false>]
There was a problem hiding this comment.
Don't you mind me reverting the change with disconnect_contacts in the account deleter?
There was a problem hiding this comment.
No, one half of the contacts are deleted via delete_contacts_of_me and the second half is deleted with deleting aspects in delete_standard_user_associations
No, delete_contacts_of_me are contacts of local people who have us in their aspects. The thing that isn't deleted are contacts where user is us, and person is someone else, while delete_contacts_of_me deletes contacts where we're a person. So that's a different thing.
There was a problem hiding this comment.
You are right, when I add your change from the DataGenerator, it fails without disconnect_contacts ... We probably need better tests, because without the additional double-sided contact, it fails without .reload. I created #7538 to fix that, that should now cover both problems.
I need to sleep now, because I'm tired and I need to work tomorrow, but I'll have a closer look at this tomorrow, to improve the tests. Or if you have the time to improve the tests in your PR, you can also do it.
There was a problem hiding this comment.
We probably need better tests
What tests exactly? Some more tests for this method in spec/lib/account_deleter_spec.rb?
There was a problem hiding this comment.
@SuperTux88, good night and thank you for your work!
There was a problem hiding this comment.
In this case: tests with different combinations of contacts. Without disconnect_contacts it fails when you have double sided contacts, for me it failed without .reload. So something that covers that.
But I just tested, when I remove the .reload it now also fails with the updated DataGenerator, so it's maybe already enough. I just want to make sure that we don't remove the .reload or disconnect_contacts and something is broken again without a failing test.
But I'll have a closer look at this again tomorrow. #7538 should fix what I broke and as it looks it also makes the tests failing if I break something again, so for now that's good enough ;) 😴
|
Your refactorings conflict with the changes from #6750. What do you think we should merge first? |
I know, that's why I already mentioned it in the PR description. Since you changed |
|
Oh, I broke the tests last minute, because pronto told me so :( I'll fix that ... |
aca64a1 to
75b69a6
Compare
|
Usage of @denschub disapproved this change back then: #6783 (comment) |
|
Hmm, I don't see why we shouldn't use |
75b69a6 to
d535ab9
Compare
Okay, I need to review this PR then to check it doesn't affect anything that I use in migration. #6750 also changes some associations in objects and in |
That's what I thought either, but I changed it to this |
If we already have inside the current worker, that's totally fine, but passing around objects between worker causes them to get serialized to redis, which is a bit of a bummer. However, it does not seem like we end up with that here, so I may made a brainfart in the comment back then. |
I checked while editing this (but that was before your latest push), and you extacted the I didn't change anything |
|
Also, tests fixed (travis is still busy with your PR) :) |
denschub
left a comment
There was a problem hiding this comment.
Take this as approved once travis is green.
| end | ||
|
|
||
| context "of local user" do | ||
| subject(:user) { FactoryGirl.create(:user_with_aspect) } |
There was a problem hiding this comment.
I'd rahter not change this part here since it will be hard to rebase. Maybe it's better to add this change on top of my PR instead?
There was a problem hiding this comment.
(this applies to most of the changes in this file, maybe excluding line 3)
Also remove `disconnect_contacts` methods, because contacts are already removed with aspects memberships in `before_destroy`.
d535ab9 to
dbde75a
Compare
Add missing indexes from #7234
I added the indexes reviewed by @CSammy from #7234 (comment)
I also refactored the
AccountDeleterto work with the person, that can be used in #6750 too.I didn't add the unique index for the
guidin theparticipationstable. We already have an index there and we have a unique index for thetargetwhich should be enough. I planned to remove theguidcolumn anyway soon, because we don't really need it, so there is no need to change the existing index to a unique index there.