diff --git a/paper_atlas/audits/coverage.py b/paper_atlas/audits/coverage.py index 277da70..42db2b8 100644 --- a/paper_atlas/audits/coverage.py +++ b/paper_atlas/audits/coverage.py @@ -47,6 +47,16 @@ def report(db, registry, *, pg_service=None, pg_schema=None): database, schema = str(Path(db).resolve()), None latest = _status_counts(connection, latest=True) observations = _status_counts(connection, latest=False) + # Aggregate the paper join once for the whole snapshot. Repeating it + # for each registry target caused repeated scans on the production DB. + edition_counts = {} + for row in connection.execute('''SELECT s.edition_id,count(s.id) AS submissions, + count(DISTINCT s.paper_id) AS papers, + count(DISTINCT CASE WHEN p.abstract IS NULL OR p.abstract='' THEN s.paper_id END) + AS papers_without_abstract_text + FROM submissions s LEFT JOIN papers p ON p.id=s.paper_id GROUP BY s.edition_id'''): + entry = dict(row) + edition_counts[entry.pop('edition_id')] = entry source_counts = defaultdict(list) for row in connection.execute('''SELECT s.edition_id,so.name AS source, count(DISTINCT sr.id) AS source_records, @@ -63,14 +73,12 @@ def report(db, registry, *, pg_service=None, pg_schema=None): params = (acronym, acronym) editions = [] for row in connection.execute('''SELECT e.id,v.id AS venue_id,v.acronym AS canonical_venue, - e.year,e.track,count(s.id) AS submissions,count(DISTINCT s.paper_id) AS papers, - count(DISTINCT CASE WHEN p.abstract IS NULL OR p.abstract='' THEN s.paper_id END) - AS papers_without_abstract_text - FROM editions e JOIN venues v ON v.id=e.venue_id - LEFT JOIN submissions s ON s.edition_id=e.id LEFT JOIN papers p ON p.id=s.paper_id - WHERE ''' + scope + ''' GROUP BY e.id,v.id,v.acronym,e.year,e.track + e.year,e.track FROM editions e JOIN venues v ON v.id=e.venue_id + WHERE ''' + scope + ''' ORDER BY e.year,e.track,v.acronym''', params): edition = dict(row) + edition.update(edition_counts.get(row['id'], { + 'submissions': 0, 'papers': 0, 'papers_without_abstract_text': 0})) covered_venue_ids.add(edition['venue_id']) edition['latest_observed_status_counts'] = {status: latest[row['id']].get(status, 0) for status in STATUSES} edition['decision_observation_counts'] = {status: observations[row['id']].get(status, 0) for status in STATUSES} diff --git a/tests/test_coverage_report.py b/tests/test_coverage_report.py index bdeacfa..3d7a4a5 100644 --- a/tests/test_coverage_report.py +++ b/tests/test_coverage_report.py @@ -87,5 +87,18 @@ class CoverageTests(unittest.TestCase): report(path, self.registry) self.assertFalse(path.exists()) + def test_empty_editions_remain_visible_after_shared_aggregation(self): + self.store.conn.execute("INSERT INTO venues(acronym,name,field,venue_type) VALUES('AAAI','AAAI','general_ai','conference')") + venue = self.store.conn.execute("SELECT id FROM venues WHERE acronym='AAAI'").fetchone()[0] + self.store.conn.execute("INSERT INTO editions(venue_id,year,track) VALUES(?,2026,'main')", (venue,)) + self.store.conn.commit() + aaai = report(self.db, self.registry)['venues'][1] + self.assertEqual(aaai['history_status'], 'no_imported_records') + self.assertEqual(len(aaai['editions']), 1) + edition = aaai['editions'][0] + self.assertEqual((edition['submissions'], edition['papers'], edition['papers_without_abstract_text']), (0, 0, 0)) + self.assertEqual(sum(edition['latest_observed_status_counts'].values()), 0) + self.assertEqual(edition['source_record_counts'], []) + if __name__=='__main__':unittest.main()