From 477624404f0b038d288a095139f56ff69aa0c196 Mon Sep 17 00:00:00 2001 From: Bastian Blank Date: Thu, 30 Nov 2023 13:59:37 +0100 Subject: [PATCH] Make search actually fast enough --- src/glvd/database/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/glvd/database/__init__.py b/src/glvd/database/__init__.py index c111017..6514cfa 100644 --- a/src/glvd/database/__init__.py +++ b/src/glvd/database/__init__.py @@ -9,7 +9,10 @@ Self, ) -from sqlalchemy import ForeignKey +from sqlalchemy import ( + ForeignKey, + Index, +) from sqlalchemy.orm import ( DeclarativeBase, Mapped, @@ -94,11 +97,21 @@ class DebCve(Base): last_mod: Mapped[datetime] = mapped_column(init=False, server_default=func.now(), onupdate=func.now()) deb_source: Mapped[str] = mapped_column(primary_key=True) deb_version: Mapped[str] = mapped_column(DebVersion) - debsec_vulnerable: Mapped[bool] + debsec_vulnerable: Mapped[bool] = mapped_column() data_cpe_match: Mapped[Any] dist: Mapped[Optional[DistCpe]] = relationship(lazy='selectin', default=None) + __table_args__ = ( + Index( + 'deb_cve_search', + dist_id, + debsec_vulnerable, + deb_source, + deb_version, + ), + ) + def merge(self, other: Self) -> None: self.deb_version = other.deb_version self.debsec_vulnerable = other.debsec_vulnerable