Skip to content
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

Add missing indexes from #7234 #7533

Merged
merged 5 commits into from
Aug 13, 2017
Merged

Conversation

SuperTux88
Copy link
Member

I added the indexes reviewed by @CSammy from #7234 (comment)

I also refactored the AccountDeleter to work with the person, that can be used in #6750 too.

I didn't add the unique index for the guid in the participations table. We already have an index there and we have a unique index for the target which should be enough. I planned to remove the guid column anyway soon, because we don't really need it, so there is no need to change the existing index to a unique index there.

@SuperTux88 SuperTux88 added this to the 0.7.0.0 milestone Aug 13, 2017
@@ -69,10 +68,6 @@ def delete_standard_person_associations
end
end

def disconnect_contacts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you mind me reverting the change with disconnect_contacts in the account deleter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@denschub: can you merge #7538 as soon as travis is green?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need better tests

What tests exactly? Some more tests for this method in spec/lib/account_deleter_spec.rb?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SuperTux88, good night and thank you for your work!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ;) 😴

@cmrd-senya
Copy link
Member

Your refactorings conflict with the changes from #6750. What do you think we should merge first?

@SuperTux88
Copy link
Member Author

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 AccountDeleter in #6750 to handle persons too, you can use the change here, and you don't need this if anymore there. So I think it's cleaner to merge this first, and the conflicts should be easy to resolve (I only removed diaspora_handle, and since you don't rely on that, that shouldn't be a problem for your PR).

@SuperTux88
Copy link
Member Author

Oh, I broke the tests last minute, because pronto told me so :( I'll fix that ...

@cmrd-senya
Copy link
Member

Usage of person in AccountDeleter is what I originally was trying to do in #6783 (which I later included to #6726).

@denschub disapproved this change back then: #6783 (comment)

@SuperTux88
Copy link
Member Author

Hmm, I don't see why we shouldn't use person here, we already have it and can continue using it. It doesn't make sense to query an entity again.

@cmrd-senya
Copy link
Member

I know, that's why I already mentioned it in the PR description. Since you changed AccountDeleter in #6750 to handle persons too, you can use the change here, and you don't need this if anymore there. So I think it's cleaner to merge this first, and the conflicts should be easy to resolve (I only removed diaspora_handle, and since you don't rely on that, that shouldn't be a problem for your PR).

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 account_deleter (method normal_ar_person_associates_to_delete and friends) so that's not only diaspora_handle. I should check this I think.

@cmrd-senya
Copy link
Member

Hmm, I don't see why we shouldn't use person here, we already have it and can continue using it. It doesn't make sense to query an entity again.

That's what I thought either, but I changed it to this if approach just because of this comment.

@denschub
Copy link
Member

Hmm, I don't see why we shouldn't use person here, we already have it and can continue using it.

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.

@SuperTux88
Copy link
Member Author

SuperTux88 commented Aug 13, 2017

Okay, I need to review this PR then to check it doesn't affect anything that I use in migration.

I checked while editing this (but that was before your latest push), and you extacted the close_user to a new method, but that is an easy change and can be resolved (you need to remove disconnect_contacts there too).

I didn't change anything normal_ar_person_associates_to_delete, but I changed from %i() to %i[], because it was really hard to read because rubymine adds curly yellow lines when there is a rubocop error, and I don't see if there is a "_" or a " " ;) I but I can revert that back if you like.

@SuperTux88
Copy link
Member Author

Also, tests fixed (travis is still busy with your PR) :)

Copy link
Member

@denschub denschub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take this as approved once travis is green.

subject.reload
end

context "of local user" do
subject(:user) { FactoryGirl.create(:user_with_aspect) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(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`.
@SuperTux88 SuperTux88 merged commit dbde75a into diaspora:develop Aug 13, 2017
SuperTux88 added a commit that referenced this pull request Aug 13, 2017
@SuperTux88 SuperTux88 deleted the add-indexes branch August 13, 2017 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants