gabriel / musehub public

0057_branch_repo_name_index.py file-level

at sha256:3 · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:0 fix: fall back to any indexed mpack in read_object_bytes when push mpac… · gabriel · Jun 17, 2026
1 """Add composite (repo_id, name) index on musehub_branches.
2
3 get_branch_head_commit_id() does a point lookup WHERE repo_id = ? AND name = ?
4 on every push and fetch. Without a composite index this scans all branches for
5 the repo. list_branches_with_detail() also benefits: the composite index covers
6 both the WHERE clause and the ORDER BY name, eliminating an in-memory sort.
7
8 Revision ID: 0057
9 Revises: 0056
10 """
11 from __future__ import annotations
12
13 from alembic import op
14
15 revision = "0057"
16 down_revision = "0056"
17 branch_labels = None
18 depends_on = None
19
20
21 def upgrade() -> None:
22 op.create_index(
23 "ix_musehub_branches_repo_name",
24 "musehub_branches",
25 ["repo_id", "name"],
26 )
27 # The composite index on (repo_id, name) makes the single-column repo_id
28 # index redundant — PostgreSQL can satisfy any repo_id-only scan using the
29 # leftmost prefix of the composite index.
30 op.drop_index("ix_musehub_branches_repo_id", table_name="musehub_branches")
31
32
33 def downgrade() -> None:
34 op.create_index(
35 "ix_musehub_branches_repo_id",
36 "musehub_branches",
37 ["repo_id"],
38 )
39 op.drop_index("ix_musehub_branches_repo_name", table_name="musehub_branches")