Skip to content

Commit

Permalink
Just use ES results directly
Browse files Browse the repository at this point in the history
The query only returns docs that _don't_ have that value set, then
fetches those from couch and attempts to get that value.  However, this
information is no longer stored in couch anyways.
  • Loading branch information
esoergel committed Jun 21, 2024
1 parent 983b087 commit 675b859
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions corehq/apps/geospatial/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,32 +367,28 @@ def get_paginated_cases_without_gps(self, domain, page, limit):

def _get_paginated_users_without_gps(domain, page, limit, query):
location_prop_name = get_geo_user_property(domain)
query = (
res = (
UserES()
.domain(domain)
.mobile_users()
.missing_or_empty_user_data_property(location_prop_name)
.search_string_query(query, ['username'])
.fields(['_id', 'username'])
.sort('created_on', desc=True)
.start((page - 1) * limit)
.size(limit)
.run()
)

paginator = Paginator(query.get_ids(), limit)
user_ids_page = list(paginator.get_page(page))
user_docs = get_docs(CommCareUser.get_db(), keys=user_ids_page)
user_data = []
for user_doc in user_docs:
lat, lon = get_lat_lon_from_dict(user_doc['user_data'], location_prop_name)
user_data.append(
{
'id': user_doc['_id'],
'name': user_doc['username'].split('@')[0],
'lat': lat,
'lon': lon,
}
)
return {
'items': user_data,
'total': paginator.count,
'items': [
{
'id': hit['_id'],
'name': hit['username'].split('@')[0],
'lat': '',
'lon': '',
} for hit in res.hits
],
'total': res.total,
}


Expand Down

0 comments on commit 675b859

Please sign in to comment.