-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: List popular event locations at /event-locations #6056
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
Conversation
Codecov Report
@@ Coverage Diff @@
## development #6056 +/- ##
==============================================
- Coverage 66.15% 66.1% -0.06%
==============================================
Files 285 285
Lines 14060 14080 +20
==============================================
+ Hits 9301 9307 +6
- Misses 4759 4773 +14
Continue to review full report at Codecov.
|
app/api/helpers/scheduled_jobs.py
Outdated
| .group_by(Event.searchable_location_name)\ | ||
| .order_by(desc('counts'))\ | ||
| .limit(5) | ||
| db.session.query(EventLocation).delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine but just one doubt. Why are we running a delete on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
umm.. because if we only keep adding locations and not removing them we will have multiple copies of the same location. Every week say delhi will keep getting added. @mrsaicharan1
uds5501
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks Good
iamareebjamal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query you wrote of fetching the most popular events is not that expensive that we cache that in other table and run a cron for every 7 days. Just use that query directly
Secondly, the logic of taking serachable location name is wrong.
Suppose, there are 3 events
AMU, Aligarh
Dodhpur, Aligarh
Railway Road, Aligarh
All of them would have a count of 1 and Aligarh will never be shown. For this to work, you need exact address matches
Also, the location should be city and this will return address. Like Chandni Chowk, Delhi instead of Delhi
@iamareebjamal I don't agree with this inference. AMU, Aligarh, Dodhpur, Aligarh, Railway Road, Aligarh will all have the Also regarding, caching, do we need a separate endpoint for this then? What will we use /event-locations for as a use case, as per the discussion in the parent issue my understanding was that /event-locations should return the most recent locations.
It does not. Edit: I have printed the results after running the query on the production dataset, they were result objects of the form (Delhi, 21), (Singapore, 5) etc. |
|
@iamareebjamal The problem was that searchabeLocationName was not being filled on creating an event. @CosmicCoder96 solved it (fossasia/open-event-frontend#3150). So, this logic would work and it will only return the city name. |
prateekj117
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
@prateekj117 This implementation is agnostic of the PR you mentioned. If searcable location was null or is null which it might as well be due to various reasons, this query will (and should) return nothing. |
|
OK, if searchable location name is of city, this will work, but we still don't need a cron job for this. Please, just use the query directly. And no, we don't need a separate endpoint for this, use the event-locations endpoint only, just no need of running a cron and saving in a separate table |
|
@CosmicCoder96 It's confusing to me that searchable location name were not all null in production database, and returning saving nothing in case of development database. |
|
@prateekj117 fossasia/open-event-frontend#3150 (comment) @iamareebjamal class EventLocationList(ResourceList):
"""
List event locations
"""
def before_get(self, args, kwargs):
popular_locations = db.session.query(Event.searchable_location_name, func.count(Event.id).label('counts')) \
.group_by(Event.searchable_location_name) \
.order_by(desc('counts')) \
.limit(5)
db.session.query(EventLocation).delete()
for location, _ in popular_locations:
if location is not None:
new_location = EventLocation(location)
db.session.add(new_location)
db.session.commit() |
popular_locations = db.session.query(Event.searchable_location_name, func.count(Event.id).label('counts')) \
.group_by(Event.searchable_location_name) \
.order_by(desc('counts')) \
.limit(5)
locations = []
for location, _ in popular_locations:
if location is not None:
locations.append(EventLocation(location))
return locationsNo need of delete and insert |
|
@iamareebjamal But popular_location above just contains a query string and result sets are of the format |
|
@CosmicCoder96 Updated the command |
5350111
| new_location.id = len(locations) | ||
| locations.append(new_location) | ||
| schema = EventLocationSchema() | ||
| result = schema.dump(locations, many=True).data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamareebjamal Had to make these changes to keep it JSON-API compliant. Please review.
|
Travis failing |
|
@iamareebjamal Fixed now. |
Fixes #6054
Short description of what this resolves:
Adds a cron job, which populates and refreshes the event locations every 7 days with the most popular event locations.