Skip to content

Commit 6302a7b

Browse files
authored
Make AOI feed generation thread-safe (OSMCha#742)
1 parent 01e5227 commit 6302a7b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

osmchadjango/supervise/views.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ class AOIListChangesetsFeedView(Feed):
119119
"""
120120

121121
def get_object(self, request, pk):
122-
self.feed_id = pk
123122
return AreaOfInterest.objects.get(pk=pk)
124123

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

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

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

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

145155
def item_pubdate(self, item):
146156
return item.date

0 commit comments

Comments
 (0)