Skip to content

clean up endorsements with no valid skills #285

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

Merged
merged 1 commit into from
Jan 8, 2015

Conversation

avinoth
Copy link
Contributor

@avinoth avinoth commented Jan 6, 2015

There are some rows in Endorsement where the Skills is not valid.
Make Endorsements delete if corresponding skill is deleted.

https://assembly.com/coderwall/bounties/491

@@ -0,0 +1,11 @@
class CleanupEndorsements < ActiveRecord::Migration
def up
Endorsement.find_each(batch_size: 100) do |endo|
Copy link
Contributor

Choose a reason for hiding this comment

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

we could use delete_all(condition)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought finding in batches wouldn't clog the memory.. Not sure about delete_all way of handling though. You want me to rewrite it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think delete_all would be the way to go since it would be a single SQL query without having to build up any ruby objects. But you'll have to change the query to something like:

Endorsement.where(endorsing_user_id: nil).delete_all

Not sure if that covers the case where there's a broken endorsing_user_id foreign key.

Copy link
Contributor

Choose a reason for hiding this comment

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

Endorsement.delete_all(endorsing_user_id: [nil,''])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool.. i ll rewrite then..

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.. created new migration just incase..

avinoth@4b7319e

@vanstee
Copy link
Contributor

vanstee commented Jan 6, 2015

LGTM

@seuros
Copy link
Contributor

seuros commented Jan 6, 2015

Nice work. Could you squash your commits ?

@avinoth
Copy link
Contributor Author

avinoth commented Jan 6, 2015

Sure..

@avinoth
Copy link
Contributor Author

avinoth commented Jan 6, 2015

Alright.. So I squashed em and it is showing as only one commit in my local repo, but adds more and more while I push.. messed up somewhere.. Shall I ignore this PR altogether and start a new one since I am afraid the history would rewritten if I try squashing again..

Anyone has suggestions?

@avinoth
Copy link
Contributor Author

avinoth commented Jan 6, 2015

Fine.. I am getting a fresh copy and would send a new PR.. let's dump this..

@avinoth avinoth closed this Jan 6, 2015
@seuros
Copy link
Contributor

seuros commented Jan 6, 2015

@avinoth: git push -f

@avinoth
Copy link
Contributor Author

avinoth commented Jan 6, 2015

The rebase messed up.. got a clean copy and did force push.. 👍

@juanroldan1989
Copy link

Hello,

I would rather implement find_in_batches inside a task instead of a migration:

http://apidock.com/rails/ActiveRecord/Batches/find_in_batches

Also with find_in_batches you can define the size of the batch to process.

Cheers,

Juan.

@avinoth avinoth changed the title clean up endorsements with no valid endorsers clean up endorsements with no valid skills Jan 8, 2015
@avinoth
Copy link
Contributor Author

avinoth commented Jan 8, 2015

All set now.. changed the title and comments accordingly..

seuros added a commit that referenced this pull request Jan 8, 2015
clean up endorsements with no valid skills
@seuros seuros merged commit d24d28a into coderwall:master Jan 8, 2015
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.

4 participants