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

Performance: is_verified system field performance bottleneck #1013

Open
1 of 2 tasks
ntarocco opened this issue Sep 15, 2023 · 0 comments
Open
1 of 2 tasks

Performance: is_verified system field performance bottleneck #1013

ntarocco opened this issue Sep 15, 2023 · 0 comments

Comments

@ntarocco
Copy link
Contributor

ntarocco commented Sep 15, 2023

The is_verified fetch all members of the community, with a DB query.
This leads to 2 issues:

  • if a request like /api/communities, multiple DB query are performed
  • it looks like that cls(obj.data, model=obj) in get_members, used by the system fields, triggers an UPDATE query:
File "/usr/local/lib/python3.9/site-packages/invenio_communities/communities/records/systemfields/is_verified.py", line 25, in calculate
    owners = [m.dumps() for m in Member.get_members(record.id) if m.role == "owner"]
  File "/usr/local/lib/python3.9/site-packages/invenio_communities/members/records/api.py", line 153, in get_members
    return [cls(obj.data, model=obj) for obj in q.all()]
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/query.py", line 2773, in all
    return self._iter().all()
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/query.py", line 2916, in _iter
    result = self.session.execute(
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/session.py", line 1665, in execute
    ) = compile_state_cls.orm_pre_session_exec(
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/context.py", line 312, in orm_pre_session_exec
    session._autoflush()
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/session.py", line 2253, in _autoflush
    self.flush()
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/session.py", line 3449, in flush
    self._flush(objects)
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/session.py", line 3549, in _flush
    flush_context.execute()
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
    util.preloaded.orm_persistence.save_obj(
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 237, in save_obj
    _emit_update_statements(
  File "/usr/local/lib64/python3.9/site-packages/sqlalchemy/orm/persistence.py", line 975, in _emit_update_statements

Related fixes:

@lnielsen lnielsen changed the title is_verified system field performance bottleneck Performance: is_verified system field performance bottleneck Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants