Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Speed up tip migration. Fixes #3894 #3904

Merged
merged 3 commits into from
Jan 24, 2016
Merged

Speed up tip migration. Fixes #3894 #3904

merged 3 commits into from
Jan 24, 2016

Conversation

aandis
Copy link
Contributor

@aandis aandis commented Jan 23, 2016

@rohitpaulk , @whit537 tests are failing as of now. If this looks good, I'll go ahead and fix them. ;)

#3894

@aandis aandis added the Review label Jan 23, 2016
@@ -158,19 +158,6 @@ def to_dict(self):
}

def migrate_tips(self):
payment_instructions = self.db.all("""
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 the basic filtering done above should be good enough - removing this check might do more harm than good.

We generally have 5-10 new teams every week, and ~150 teams in total. Adding the first check alone brings down the number of DB calls from 300 (150 * 2) to 20 (10 * 2). Removing this second check would bring that number down to 10 - but wouldn't give us the flexibility to blindly call Team.migrate_tips over the console. Also, the migrate-tips.py script isn't covered by our test suite, but Team.migrate_tips is.

Thoughts?

@aandis aandis force-pushed the speed-up-tip-migration branch from 76081fb to 0707b59 Compare January 24, 2016 09:39
JOIN tips ON t.owner = tips.tippee -- Only fetch teams whose owner have tips.
WHERE t.is_approved IS TRUE -- Only fetch approved teams.
AND NOT EXISTS ( -- Make sure not already migrated.
SELECT 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dammit why doesn't this align. Looks fine in the editor. 😠

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rohitpaulk do you have any idea why the comment looks funny here but looks fine in the editor?
screenshot from 2016-01-24 15 25 09 😡

Copy link
Contributor

Choose a reason for hiding this comment

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

Most likely spaces vs tabs..

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, confirmed.

screen shot 2016-01-24 at 3 31 37 pm

This is sublime text - See the difference? The .s are spaces, and -s are tabs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to only spaces. Should work now.

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

@rohitpaulk changes made. Also incorporated changes discussed in 3aba842

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

Let me know if I should undo 0707b59

@rohitpaulk
Copy link
Contributor

Let me know if I should undo 0707b59

I think it'd make sense to undo it.

""")

for slug in slugs:
team = Team.from_slug(slug)
for team in teams:
try:
ntips = team.migrate_tips()
print("Migrated {} tip(s) for '{}'".format(ntips, slug))
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace slug with team.slug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops. missed that.

@aandis aandis force-pushed the speed-up-tip-migration branch from 0707b59 to fb9e25f Compare January 24, 2016 10:21
@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

@rohitpaulk done! Since migrate-tips.py isn't covered by the test suite, can you somehow run this and test that the new query works as expected? If it does, I think we are good to go.

@rohitpaulk
Copy link
Contributor

I've been running this on my local, yes - That's how I discovered #3904 (comment) :)

Are you not able to run this script yourself? Is fake data completely broken?

@rohitpaulk
Copy link
Contributor

Once I have fake data in the DB, I use ./env/bin/honcho run -e defaults.env ./env/bin/python ./bin/migrate-tips.py to run the script

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

Thing is, my fake data doesn't have any teams which satisfy the two where conditions simultaneously. So it just exits with Done. Hence I can't be 100% sure it does what we expect it to do. I'll have to create all those rows manually first to test. 😫
If you are able to run and see expected outputs, we can merge this.

@rohitpaulk
Copy link
Contributor

Works fine for me, yes - Travis seems to be complaining about something, can you fix that?

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

Builds are passing for this pr. What is wrong?

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

Oh import error I guess.

@rohitpaulk
Copy link
Contributor

Builds are passing for this pr.

They're still 🔴, we want 🍏!

@aandis aandis force-pushed the speed-up-tip-migration branch from fb9e25f to 3a16561 Compare January 24, 2016 10:55
@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

There's your green 🍎 😛

@rohitpaulk
Copy link
Contributor

@aandis - I've added a commit, go ahead and merge if it looks good to you

@rohitpaulk
Copy link
Contributor

http://sqlfiddle.com/#!15/20a13/5

@aandis - Is that accessible to you?

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

Yes, Checking it out.

@rohitpaulk
Copy link
Contributor

teams.owner is unique too because it references participant.username. So a slug can only belong to one owner.

teams.owner need not be unique - by referencing participant.username, the only constraint we're placing on the column is that the value has to have a corresponding record in the participants table. It's possible for one owner to have multiple teams. Example: https://gratipay.com/~bbatsov/

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

Yep. Got it. #3894 described restriction on team hence the misunderstanding.

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

I'll merge this then. This was fun. :-)

aandis added a commit that referenced this pull request Jan 24, 2016
@aandis aandis merged commit e8d358b into master Jan 24, 2016
@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

Ok merged. Do I change the version now? What is the criteria for changing version?

@aandis aandis deleted the speed-up-tip-migration branch January 24, 2016 13:14
@rohitpaulk
Copy link
Contributor

Do I change the version now? What is the criteria for changing version?

That happens automatically as part of the release process when we ship code to Heroku :)

@aandis
Copy link
Contributor Author

aandis commented Jan 24, 2016

Cool! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants