Skip to content

Conversation

@JVickery-TBS
Copy link

feat(dev): ds return backport;

  • Return records capability.
  • Improved ds upsert sql.

ckan#8684

- Return records capability.
- Improved ds upsert sql.
- Added change log file.
return_columns=return_columns) if data_dict[
'include_records'] else '',
values=('%s, ' % pk_values_sql if pk_sql == '"_id"' else '') +
', '.join([f'cast(:{p} as nested)' if field['type'] == 'nested'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this nested type haunts the datastore code base since before postgres had a built-in json type 👻

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r we fixing it upstream eventually?

# (canada fork only): https://github.com/ckan/ckan/pull/8684
results =_execute_single_statement(context, sql_string, where_values)
if data_dict['include_records']:
data_dict['deleted_records'] = [dict(r) for r in results.mappings().all()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see this causing a MemoryError when deleting all the rows in a large table.

For dsaudit we only need the first N rows to populate the activity. Can we apply a LIMIT to a DELETE ... RETURNING?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have to do something like this I guess: https://stackoverflow.com/a/37043809

which would require some bigger sql statement changes which could be done. This code is for my datastore solr index plugin, so I would need to have all of the deleted records I think?

result.pop('connection_url', None)
# (canada fork only): https://github.com/ckan/ckan/pull/8684
if not data_dict.pop('include_records', False):
result.pop('deleted_records', None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all of the other endpoints "include_records" adds a "records" value to the return but datastore_delete is different?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, just semantically for API users to make it clear that the records were deleted

- Upstream PR changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants