Skip to content

Commit

Permalink
Change to left join to handle situaton where submission was made anon…
Browse files Browse the repository at this point in the history
…ymously
  • Loading branch information
denniswambua committed Nov 18, 2021
1 parent 3823465 commit 2c7d116
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions onadata/libs/data/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ def _postgres_count_group(field, name, xform, data_view=None):
if data_view:
additional_filters = _additional_data_view_filters(data_view)

# Use inner join to the auth user model for better performance.
# Use left join to the auth user model for better performance.
if field == "_submitted_by":
string_args["json"] = "au.username"
string_args["inner_join"] = "i INNER JOIN auth_user au ON au.id = i.user_id"
string_args["join"] = "i LEFT JOIN auth_user au ON au.id = i.user_id"

restricted_string = _restricted_query(xform)
sql_query = "SELECT %(json)s AS \"%(name)s\", COUNT(*) AS count FROM " \
"%(table)s %(inner_join)s WHERE " + restricted_string + \
"%(table)s %(join)s WHERE " + restricted_string + \
" AND deleted_at IS NULL " + additional_filters + " GROUP BY %(json)s"\
" ORDER BY %(json)s"
sql_query = sql_query % string_args
Expand Down Expand Up @@ -170,7 +170,7 @@ def _query_args(field, name, xform, group_by=None):
'name': name,
'restrict_field': 'xform_id',
'restrict_value': xform.pk,
'inner_join': '',
'join': '',
}

if xform.is_merged_dataset:
Expand Down

0 comments on commit 2c7d116

Please sign in to comment.