Automattic / camptix

Moved to https://github.com/WordPress/wordcamp.org/
177 stars 97 forks source link

Memoize buyer data to save SQL queries to figure out ticket buyer of … #236

Closed vedanshujain closed 5 years ago

vedanshujain commented 5 years ago

…an attendee.

Attendee data export was timing out for 2018.us.wordcamp.org. Apparently the bottleneck was figuring out the buyer data. We were making meta queries to figure out the attendee buyer data resulting in an n+1 query pattern. Given how we insert buyer data, we can just treat first attendee with a different access_token, to be the ticker buyer for rest of the attendees of with the same access token.

vedanshujain commented 5 years ago

This is still taking about 35s on my sandbox though. I have ideas to optimize it further, but that will need bigger code change than this one.

vedanshujain commented 5 years ago

Ok so I managed to get this in about 10s - 12s.

@iandunn @coreymckrill Here is the data for this PR Earlier: ~50s (per 200 records for ~4.8k records) After commit https://github.com/Automattic/camptix/pull/236/commits/e3a8dc73587451a9adeea63e5904d5c0fbf7114f : ~2s (for 200 records) After commit https://github.com/Automattic/camptix/pull/236/commits/31abe6a7b3cdb7db44e1274a90d5dd59aa4caea4 : ~1s (for 200 records) After commit https://github.com/Automattic/camptix/pull/236/commits/2a2213dac1bf85fc198e4f23d297a8bf06a4af06 : ~10s (for about 4.8k records)

I tested this by comparing attendee report for couple of camps before and after the changes.

iandunn commented 5 years ago

Once this is merged, it'd be good to sync any esc_csv() changes with WordCamp\Utilities\Export_CSV.

vedanshujain commented 5 years ago

@iandunn @coreymckrill After mbstring getting installed, this is now about ~10s. So I am going to go ahead and merge this.