From 6cde279e8034ecd18b5101ab39ef5ec565f2897c Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 3 Nov 2023 13:21:57 +0100 Subject: [PATCH] database:files_db - add checksum count view to count occurrences of files --- acacore/database/files_db.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/acacore/database/files_db.py b/acacore/database/files_db.py index 7a34fae..0cd6946 100644 --- a/acacore/database/files_db.py +++ b/acacore/database/files_db.py @@ -9,6 +9,7 @@ from acacore.models.file import ConvertedFile from acacore.models.file import File from acacore.models.history import HistoryEntry +from acacore.models.identification import ChecksumCount from acacore.models.identification import SignatureCount from acacore.models.metadata import Metadata from acacore.utils.functions import or_none @@ -78,6 +79,34 @@ def __init__( self.files.model, f'"{self.files.name}".warning IS NOT null', ) + self.checksum_count = self.create_view( + "_ChecksumCount", + self.files, + ChecksumCount, + None, + [ + Column("checksum", "varchar", str, str, False, False, False), + ], + [ + (Column("count", "int", str, str), "ASC"), + ], + select_columns=[ + Column( + "checksum", + "varchar", + or_none(str), + or_none(str), + False, + False, + False, + ), + SelectColumn( + f'count("{self.files.name}.checksum")', + int, + "count", + ), + ], + ) self.signature_count = self.create_view( "_SignatureCount", self.files,