Skip to content

Commit 0e8329b

Browse files
improve query performance
1 parent 8c20f5c commit 0e8329b

File tree

8 files changed

+93
-6
lines changed

8 files changed

+93
-6
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""add indexes
2+
3+
Revision ID: aa2c85e8a66a
4+
Revises: 48604dfdc5f4
5+
Create Date: 2025-04-03 15:45:02.586547+00:00
6+
7+
"""
8+
9+
from alembic import op
10+
11+
# revision identifiers, used by Alembic.
12+
revision = "aa2c85e8a66a"
13+
down_revision = "48604dfdc5f4"
14+
branch_labels = None
15+
depends_on = None
16+
17+
18+
def upgrade():
19+
# ### commands auto generated by Alembic - please adjust! ###
20+
op.create_index(
21+
"idx_project_to_groups_gid", "project_to_groups", ["gid"], unique=False
22+
)
23+
op.create_index(
24+
"idx_projects_last_change_date_desc",
25+
"projects",
26+
["last_change_date"],
27+
unique=False,
28+
postgresql_using="btree",
29+
postgresql_ops={"last_change_date": "DESC"},
30+
)
31+
op.create_index("idx_projects_type", "projects", ["type"], unique=False)
32+
op.create_index(
33+
"idx_project_to_folders_project_uuid",
34+
"projects_to_folders",
35+
["project_uuid"],
36+
unique=False,
37+
)
38+
op.create_index(
39+
"idx_project_to_folders_user_id",
40+
"projects_to_folders",
41+
["user_id"],
42+
unique=False,
43+
)
44+
op.create_index(
45+
"idx_projects_to_products_product_name",
46+
"projects_to_products",
47+
["product_name"],
48+
unique=False,
49+
)
50+
op.create_index(
51+
"idx_workspaces_access_rights_gid",
52+
"workspaces_access_rights",
53+
["gid"],
54+
unique=False,
55+
)
56+
# ### end Alembic commands ###
57+
58+
59+
def downgrade():
60+
# ### commands auto generated by Alembic - please adjust! ###
61+
op.drop_index(
62+
"idx_workspaces_access_rights_gid", table_name="workspaces_access_rights"
63+
)
64+
op.drop_index(
65+
"idx_projects_to_products_product_name", table_name="projects_to_products"
66+
)
67+
op.drop_index("idx_project_to_folders_user_id", table_name="projects_to_folders")
68+
op.drop_index(
69+
"idx_project_to_folders_project_uuid", table_name="projects_to_folders"
70+
)
71+
op.drop_index("idx_projects_type", table_name="projects")
72+
op.drop_index(
73+
"idx_projects_last_change_date_desc",
74+
table_name="projects",
75+
postgresql_using="btree",
76+
postgresql_ops={"last_change_date": "DESC"},
77+
)
78+
op.drop_index("idx_project_to_groups_gid", table_name="project_to_groups")
79+
# ### end Alembic commands ###

packages/postgres-database/src/simcore_postgres_database/models/project_to_groups.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@
6060
column_created_datetime(timezone=True),
6161
column_modified_datetime(timezone=True),
6262
sa.UniqueConstraint("project_uuid", "gid"),
63+
sa.Index("idx_project_to_groups_gid", "gid"),
6364
)

packages/postgres-database/src/simcore_postgres_database/models/projects.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
""" Projects table
1+
"""Projects table"""
22

3-
"""
43
import enum
54

65
import sqlalchemy as sa
@@ -171,6 +170,14 @@ class ProjectType(enum.Enum):
171170
server_default=sa.text("'{}'::jsonb"),
172171
doc="DEPRECATED: Read/write/delete access rights of each group (gid) on this project",
173172
),
173+
### INDEXES ----------------------------
174+
sa.Index("idx_projects_type", "type"),
175+
sa.Index(
176+
"idx_projects_last_change_date_desc",
177+
"last_change_date",
178+
postgresql_using="btree",
179+
postgresql_ops={"last_change_date": "DESC"},
180+
),
174181
)
175182

176183

packages/postgres-database/src/simcore_postgres_database/models/projects_to_folders.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@
4242
column_created_datetime(timezone=True),
4343
column_modified_datetime(timezone=True),
4444
sa.UniqueConstraint("project_uuid", "folder_id", "user_id"),
45+
sa.Index("idx_project_to_folders_project_uuid", "project_uuid"),
46+
sa.Index("idx_project_to_folders_user_id", "user_id"),
4547
)

packages/postgres-database/src/simcore_postgres_database/models/projects_to_products.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434
column_created_datetime(timezone=False),
3535
column_modified_datetime(timezone=False),
3636
sa.UniqueConstraint("project_uuid", "product_name"),
37+
sa.Index("idx_projects_to_products_product_name", "product_name"),
3738
)

packages/postgres-database/src/simcore_postgres_database/models/workspaces_access_rights.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@
5757
column_created_datetime(timezone=True),
5858
column_modified_datetime(timezone=True),
5959
sa.UniqueConstraint("workspace_id", "gid"),
60+
sa.Index("idx_workspaces_access_rights_gid", "gid"),
6061
)

services/web/server/src/simcore_service_webserver/projects/_crud_api_read.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ async def list_projects_full_depth(
199199
folder_query=FolderQuery(folder_scope=FolderScope.ALL),
200200
filter_trashed=trashed,
201201
filter_by_services=user_available_services,
202-
filter_tag_ids_list=tag_ids_list,
203202
filter_by_project_type=ProjectType.STANDARD,
204203
search_by_multi_columns=search_by_multi_columns,
205204
search_by_project_name=search_by_project_name,

services/web/server/src/simcore_service_webserver/projects/_projects_repository_legacy.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
ANY_USER_ID_SENTINEL,
8080
BaseProjectDB,
8181
ProjectAccessRights,
82-
assemble_array_groups,
8382
convert_to_db_names,
8483
convert_to_schema_names,
8584
create_project_access_rights,
@@ -656,7 +655,6 @@ async def list_projects_dicts( # pylint: disable=too-many-arguments,too-many-st
656655
user_groups_proxy: list[RowProxy] = await self._list_user_groups(
657656
conn, user_id
658657
)
659-
user_groups_array_str = assemble_array_groups(user_groups_proxy)
660658
user_groups: list[int] = [group.gid for group in user_groups_proxy]
661659

662660
###
@@ -668,7 +666,6 @@ async def list_projects_dicts( # pylint: disable=too-many-arguments,too-many-st
668666
user_id=user_id,
669667
workspace_query=workspace_query,
670668
is_search_by_multi_columns=search_by_multi_columns is not None,
671-
user_groups_array_str=user_groups_array_str,
672669
user_groups=user_groups,
673670
)
674671

0 commit comments

Comments
 (0)