Skip to content

Commit

Permalink
Make AOI feed generation thread-safe (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-low authored Feb 6, 2025
1 parent 01e5227 commit 6302a7b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions osmchadjango/supervise/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class AOIListChangesetsFeedView(Feed):
"""

def get_object(self, request, pk):
self.feed_id = pk
return AreaOfInterest.objects.get(pk=pk)

def title(self, obj):
Expand All @@ -131,7 +130,16 @@ def link(self, obj):
return reverse('supervise:aoi-detail', args=[obj.id])

def items(self, obj):
return obj.changesets()[:50]
items = obj.changesets()[:50]
# HACK: we want the <link> for each feed <item> to contain both the
# changeset ID and the AOI ID, but only the changeset is available in
# item_link() (passed in as the 'item' argument). As a workaround we'll
# attach the AOI ID to each changeset object. Storing the AOI ID on
# 'self' is tempting, but not thread-safe, since a single instance of
# the Feed class is used to serve all feed requests.
for item in items:
item.aoi_id = obj.id
return items

def item_title(self, item):
return 'Changeset {} by {}'.format(item.id, item.user)
Expand All @@ -140,7 +148,9 @@ def item_geometry(self, item):
return item.bbox

def item_link(self, item):
return "{}/changesets/{}/?aoi={}".format(settings.OSMCHA_URL, item.id, self.feed_id)
# item.aoi_id is obj.id, i.e. the UUID (pk) from the request URL,
# as set by us in items(self, obj) above.
return "{}/changesets/{}/?aoi={}".format(settings.OSMCHA_URL, item.id, item.aoi_id)

def item_pubdate(self, item):
return item.date
Expand Down

0 comments on commit 6302a7b

Please sign in to comment.