Skip to content
Snippets Groups Projects
Verified Commit 6c7e2749 authored by Kevin Morris's avatar Kevin Morris
Browse files

feat(db): add an index for SSHPubKeys.PubKey (#2)


Speeds up SSHPubKeys.PubKey searches in a larger database.

Fixed form of the original commit which was reverted,
1a7f6e1f

Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 5abd5db3
No related branches found
No related tags found
No related merge requests found
Pipeline #24598 passed
......@@ -87,6 +87,8 @@ SSHPubKeys = Table(
Column('UserID', ForeignKey('Users.ID', ondelete='CASCADE'), nullable=False),
Column('Fingerprint', String(44), primary_key=True),
Column('PubKey', String(4096), nullable=False),
Index('SSHPubKeysUserID', 'UserID'),
Index('SSHPubKeysPubKey', 'PubKey'),
mysql_engine='InnoDB', mysql_charset='utf8mb4', mysql_collate='utf8mb4_bin',
)
......
"""add SSHPubKeys.PubKey index
Revision ID: dd70103d2e82
Revises: d64e5571bc8d
Create Date: 2022-08-12 21:30:26.155465
"""
import traceback
from alembic import op
# revision identifiers, used by Alembic.
revision = 'dd70103d2e82'
down_revision = 'd64e5571bc8d'
branch_labels = None
depends_on = None
def upgrade():
try:
op.create_index("SSHPubKeysUserID", "SSHPubKeys", ["UserID"])
except Exception:
traceback.print_exc()
print("failing silently...")
try:
op.create_index("SSHPubKeysPubKey", "SSHPubKeys", ["PubKey"])
except Exception:
traceback.print_exc()
print("failing silently...")
def downgrade():
op.drop_index("SSHPubKeysPubKey", "SSHPubKeys")
op.drop_index("SSHPubKeysUserID", "SSHPubKeys")
import pytest
from sqlalchemy import inspect
from aurweb.db import get_engine
from aurweb.models.ssh_pub_key import SSHPubKey
@pytest.fixture(autouse=True)
def setup(db_test):
return
def test_sshpubkeys_pubkey_index():
insp = inspect(get_engine())
indexes = insp.get_indexes(SSHPubKey.__tablename__)
found_pk = False
for idx in indexes:
if idx.get("name") == "SSHPubKeysPubKey":
assert idx.get("column_names") == ["PubKey"]
found_pk = True
assert found_pk
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment