Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manager: improe copy func #542

Merged
merged 1 commit into from
Jan 18, 2024
Merged

Conversation

jrcastro2
Copy link
Contributor

@jrcastro2 jrcastro2 commented Nov 3, 2023

@zzacharo zzacharo force-pushed the manager-copy-many branch 2 times, most recently from a1f9de6 to dc64686 Compare November 21, 2023 17:30
@zzacharo zzacharo marked this pull request as ready for review November 21, 2023 17:31
@@ -66,13 +66,14 @@ def get_by_key(cls, record_id, key):
@classmethod
def list_by_record(cls, record_id, with_deleted=False):
"""List all record files by record ID."""
query = cls.model_cls.query.filter(cls.model_cls.record_id == record_id)
with db.session.no_autoflush:
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure about this change, could you explain how does it help?

Copy link
Member

Choose a reason for hiding this comment

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

I think it was leftover from @jrcastro2 but in principle this is the fix we apply in other places instructing sqlalchemy not to trigger UPDATE queries when fetching from db. Is that the question?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It helps very little, concretely it prevents 2 more queries to the DB every time this is called, the no_autoflush is useful when we are only querying, without executing any modifications on the data. Otherwise it can lead to inconsistent data. We can remove it if it's too complicated as the real gains are very little in this case.

self._entries = {}
for rf in self.file_cls.list_by_record(self.record.id):
self._entries[rf.key] = rf
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

could we split this if statement to separate two methods instead? we know that the above block is used only while editing already published record, so we can use it directly

Copy link
Member

Choose a reason for hiding this comment

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

I agree, but the point was not to change the existing chain of calls i.e draft_files.copy(record_files). I can do it if we align with @slint as we had discussed IRL and we said that this could be done later.

* closes zenodo/rdm-project#508

Co-authored-by: Javier Romero Castro <[email protected]>
Co-authored-by: Karolina Przerwa <[email protected]>
@@ -54,7 +54,7 @@ tests =
invenio-db[postgresql,mysql,versioning]>=1.0.14,<2.0.0
pytest-invenio>=2.1.0,<3.0.0
pytest-mock>=1.6.0
sphinx>=4.2.0,<5
sphinx>=5,<6
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to update this in order for the tests to pass, the error was caused by one of the extensions
Screenshot from 2024-01-15 15-07-05
Apparently it was introduced some time ago but there was a release recently that maybe it's being picked up now, see here changelog.
The other alternative is to pin the extensions to <1.0.5

@slint slint merged commit 0576aaf into inveniosoftware:master Jan 18, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants