Skip to content

Commit c7e2567

Browse files
authored
chore: add composite index for journals (#17404)
In admin UI we fetch the 50 latest, so create a composite index that serves that use case. Signed-off-by: Mike Fiedler <[email protected]>
1 parent 0d0a56e commit c7e2567

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
"""
13+
Create composite index for journals
14+
15+
Revision ID: ed4cc2ef6b0f
16+
Revises: 48a7b9ee15af
17+
Create Date: 2025-01-13 19:08:43.774259
18+
"""
19+
20+
import sqlalchemy as sa
21+
22+
from alembic import op
23+
24+
revision = "ed4cc2ef6b0f"
25+
down_revision = "5bc11bd312e5"
26+
27+
28+
def upgrade():
29+
op.get_bind().commit()
30+
with op.get_context().autocommit_block():
31+
op.execute("SET lock_timeout = 4000")
32+
op.execute("SET statement_timeout = 5000")
33+
op.create_index(
34+
"journals_submitted_by_and_reverse_date_idx",
35+
"journals",
36+
["submitted_by", sa.text("submitted_date DESC")],
37+
unique=False,
38+
if_not_exists=True,
39+
postgresql_concurrently=True,
40+
)
41+
42+
43+
def downgrade():
44+
op.drop_index("journals_submitted_by_and_reverse_date_idx", table_name="journals")

warehouse/packaging/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,13 @@ def __table_args__(cls): # noqa
998998
Index("journals_version_idx", "version"),
999999
Index("journals_submitted_by_idx", "submitted_by"),
10001000
Index("journals_submitted_date_id_idx", cls.submitted_date, cls.id),
1001+
# Composite index for journals to be able to sort by
1002+
# `submitted_by`, and `submitted_date` in descending order.
1003+
Index(
1004+
"journals_submitted_by_and_reverse_date_idx",
1005+
cls._submitted_by,
1006+
cls.submitted_date.desc(),
1007+
),
10011008
)
10021009

10031010
id: Mapped[int] = mapped_column(primary_key=True)

0 commit comments

Comments
 (0)