From 78d641b1490b8b0d2b4a5437d6af90742f3011f8 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 31 May 2023 19:23:17 +0100 Subject: scripts: Write table checksums into index. * scripts/index-genenetwork (main): Write table checksums into index. --- scripts/index-genenetwork | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'scripts') diff --git a/scripts/index-genenetwork b/scripts/index-genenetwork index b5684f2..1f649cf 100755 --- a/scripts/index-genenetwork +++ b/scripts/index-genenetwork @@ -396,6 +396,19 @@ def main(xapian_directory: str, sql_uri: str) -> None: index_query(index_phenotypes, phenotypes_query, xapian_build_directory, sql_uri) logging.info("Combining and compacting indices") xapian_compact(combined_index, list(xapian_build_directory.iterdir())) + logging.info("Writing table checksums into index") + with locked_xapian_writable_database(combined_index) as db: + # Build a (deduplicated) set of all tables referenced in + # queries. + tables = set(clause if isinstance(clause, str) else clause.table + for clause in genes_query.tables + phenotypes_query.tables) + with database_connection(sql_uri) as conn: + checksums = [ + result["Checksum"].bind(str) # type: ignore + for result in query_sql(conn, f"CHECKSUM TABLE {', '.join(tables)}") + ] + db.set_metadata("tables", " ".join(tables)) + db.set_metadata("checksums", " ".join(checksums)) for child in combined_index.iterdir(): shutil.move(child, xapian_directory) logging.info("Index built") -- cgit v1.2.3