-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🗃️(api) add 'statique' materialized view
Having a SQL materialized view for "statique" data will ease recurrent database queries joining the same tables frequently. Moreover this will speed up database queries and response time for API endpoints using them.
- Loading branch information
Showing
11 changed files
with
220 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"jobs": [ | ||
{ | ||
"command": "*/10 * * * * python -m qualicharge refresh-static" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/api/qualicharge/migrations/versions/4b99d15436b0_add_statique_materialized_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Add statique materialized view | ||
Revision ID: 4b99d15436b0 | ||
Revises: 9ae109e209c9 | ||
Create Date: 2025-01-16 15:02:04.004411 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
from geoalchemy2.functions import ST_GeomFromEWKB | ||
from sqlalchemy_utils.view import CreateView, DropView | ||
|
||
from qualicharge.schemas.core import StatiqueMV, _StatiqueMV | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "4b99d15436b0" | ||
down_revision: Union[str, None] = "9ae109e209c9" | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
"""Create the Statique Materialized view and related indexes.""" | ||
op.execute( | ||
CreateView( | ||
_StatiqueMV.__table__.fullname, _StatiqueMV.selectable, materialized=True | ||
) | ||
) | ||
op.create_geospatial_index( | ||
"idx_statique_coordonneesXY", | ||
_StatiqueMV.__table__.fullname, | ||
[ST_GeomFromEWKB(StatiqueMV.coordonneesXY)], | ||
unique=False, | ||
postgresql_using="gist", | ||
) | ||
for idx in _StatiqueMV.__table__.indexes: | ||
idx.create(op.get_bind()) | ||
|
||
|
||
def downgrade() -> None: | ||
"""Delete the Statique Materialized View.""" | ||
|
||
op.execute( | ||
DropView(_StatiqueMV.__table__.fullname, materialized=True, cascade=True) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters