fix(analyzer): route _analyze_company_safe through cache-aware path
_analyze_company_safe was calling SERP.query directly, bypassing the SERP query cache in analyze_company. Now delegates fully to analyze_company() and reads patent_count from the serp_queries cache.
This commit is contained in:
+6
-3
@@ -182,10 +182,13 @@ class CompanyAnalyzer:
|
|||||||
CompanyAnalysisResult with success/failure status
|
CompanyAnalysisResult with success/failure status
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
patents = SERP.query(company_name)
|
# Delegate to analyze_company which handles SERP/patent caching
|
||||||
patent_count = len(patents.patents) if patents.patents else 0
|
analysis = self.analyze_company(company_name)
|
||||||
|
|
||||||
analysis = self.analyze_company(company_name, patents=patents)
|
# Determine patent count from cached SERP query
|
||||||
|
query_hash = hashlib.sha256(company_name.lower().encode()).hexdigest()
|
||||||
|
cached_ids = self.db.get_cached_serp_query(query_hash)
|
||||||
|
patent_count = len(cached_ids) if cached_ids else 0
|
||||||
|
|
||||||
# Check if analysis indicates failure
|
# Check if analysis indicates failure
|
||||||
if analysis.startswith("No patents found") or analysis.startswith(
|
if analysis.startswith("No patents found") or analysis.startswith(
|
||||||
|
|||||||
@@ -501,7 +501,7 @@ class TestBatchProcessing:
|
|||||||
|
|
||||||
assert callback.call_count == 2
|
assert callback.call_count == 2
|
||||||
|
|
||||||
def test_company_analysis_result_structure(self, mocker):
|
def test_company_analysis_result_structure(self, mocker, mock_db):
|
||||||
"""Test CompanyAnalysisResult has correct structure."""
|
"""Test CompanyAnalysisResult has correct structure."""
|
||||||
mock_query = mocker.patch("SPARC.analyzer.SERP.query")
|
mock_query = mocker.patch("SPARC.analyzer.SERP.query")
|
||||||
mock_save = mocker.patch("SPARC.analyzer.SERP.save_patents")
|
mock_save = mocker.patch("SPARC.analyzer.SERP.save_patents")
|
||||||
@@ -512,6 +512,9 @@ class TestBatchProcessing:
|
|||||||
patent = Patent(patent_id="US123", pdf_link="http://example.com/test.pdf")
|
patent = Patent(patent_id="US123", pdf_link="http://example.com/test.pdf")
|
||||||
mock_query.return_value = Patents(patents=[patent])
|
mock_query.return_value = Patents(patents=[patent])
|
||||||
|
|
||||||
|
# Simulate DB caching: after store, subsequent get returns the IDs
|
||||||
|
mock_db.get_cached_serp_query.side_effect = [None, ["US123"]]
|
||||||
|
|
||||||
def save_side_effect(p):
|
def save_side_effect(p):
|
||||||
p.pdf_path = "patents/US123.pdf"
|
p.pdf_path = "patents/US123.pdf"
|
||||||
return p
|
return p
|
||||||
|
|||||||
Reference in New Issue
Block a user