-
Notifications
You must be signed in to change notification settings - Fork 46
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
Fix performance issue #11451
base: master
Are you sure you want to change the base?
Fix performance issue #11451
Conversation
b4b6606
to
254e54f
Compare
9faa3ec
to
7621c7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh I need @arnaud-morvan here please.
|
||
import c2cgeoportal_geoportal | ||
import c2cgeoportal_geoportal.lib | ||
from c2cgeoportal_commons import models | ||
from c2cgeoportal_geoportal.lib import caching | ||
|
||
if TYPE_CHECKING: | ||
from c2cgeoportal_commons.models import main, static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waouw... is there no better way to achieve this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only way to do:
It's needed at the top for mypy.
to the running application, it will break the application because it's not yet initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strategy here seems not clear to me.
We use multiple dbsession fixtures, sometimes with transaction, sometimes not, sometimes with commit inside some function.
IMHO we should have two dbsession fixture, one which is supposed to be committed, one which should not. And if possible none based on global models.DBSession.
models.DBSession.query(Shorturl).delete() | ||
models.DBSession.query(OAuth2Client).delete() | ||
transaction.commit() | ||
with models.DBSession() as session: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO we should completely avoid using the global DBSession object and use a fixture instead, but I may miss something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to convert test_theme
then this is part of code that I want to make minimal changes...
from c2cgeoportal_commons.models.main import OGCServer | ||
|
||
transaction.commit() | ||
ogcserver = OGCServer(name="__test_ogc_server") | ||
session.flush() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should flush at end of changes instead of before.
It would be really easier to debug.
Error would raise in function which made a mistake.
Also note that here pretty sure next SELECT will raise a flush.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied in #11460
@@ -46,23 +56,51 @@ def settings(): | |||
|
|||
|
|||
@pytest.fixture | |||
def dbsession(settings): | |||
def dbsession_old(settings: dict[str, Any]) -> Session: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we keep it, we could find a better name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal: dbsession_old_version
?
The perfomance issue fix LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strategy here seems not clear to me.
We use multiple dbsession fixtures, sometimes with transaction, sometimes not, sometimes with commit inside some function.
The idea is to have the test_theme
test clean as it should be and to the minimal changes for the other tests to make them work.
IMHO we should have two dbsession fixture, one which is supposed to be committed, one which should not. And if possible none based on global models.DBSession.
Effectively, we have many tests that not relay clear and require bad session...
The goal is to do one step in the right direction.
models.DBSession.query(Shorturl).delete() | ||
models.DBSession.query(OAuth2Client).delete() | ||
transaction.commit() | ||
with models.DBSession() as session: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to convert test_theme
then this is part of code that I want to make minimal changes...
@@ -46,23 +56,51 @@ def settings(): | |||
|
|||
|
|||
@pytest.fixture | |||
def dbsession(settings): | |||
def dbsession_old(settings: dict[str, Any]) -> Session: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal: dbsession_old_version
?
|
||
import c2cgeoportal_geoportal | ||
import c2cgeoportal_geoportal.lib | ||
from c2cgeoportal_commons import models | ||
from c2cgeoportal_geoportal.lib import caching | ||
|
||
if TYPE_CHECKING: | ||
from c2cgeoportal_commons.models import main, static |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only way to do:
It's needed at the top for mypy.
to the running application, it will break the application because it's not yet initialized.
from c2cgeoportal_commons.models.main import OGCServer | ||
|
||
transaction.commit() | ||
ogcserver = OGCServer(name="__test_ogc_server") | ||
session.flush() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied in #11460
How about merging only the performance fix here, and discuss about tests refactoring in #11460 |
Fix: https://camptocamp.sentry.io/issues/5600078816/
See also: https://docs.sentry.io/product/issues/issue-details/performance-issues/n-one-queries/