Fix cache bypassing temporal company matching
- Cache lookup now validates company existed at claimed start date - If cached company was incorporated after employment date, search for alternatives - Fixes matching wrong company when cached data points to newer company Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,12 +51,24 @@ public sealed class CompanyVerifierService : ICompanyVerifierService
|
||||
_logger.LogDebug("Verifying company: {CompanyName}", companyName);
|
||||
var flags = new List<CompanyVerificationFlag>();
|
||||
|
||||
// Try to find a cached match first
|
||||
// Try to find a cached match first (but only if it existed at claimed start date)
|
||||
var cachedMatch = await FindCachedMatchAsync(companyName);
|
||||
if (cachedMatch is not null)
|
||||
{
|
||||
_logger.LogDebug("Found cached company match for: {CompanyName}", companyName);
|
||||
return CreateResultFromCache(cachedMatch, companyName, startDate, endDate, jobTitle, flags);
|
||||
// Check if cached company existed at the claimed start date
|
||||
var cacheValid = !startDate.HasValue ||
|
||||
cachedMatch.IncorporationDate == null ||
|
||||
cachedMatch.IncorporationDate <= startDate.Value;
|
||||
|
||||
if (cacheValid)
|
||||
{
|
||||
_logger.LogDebug("Found cached company match for: {CompanyName}", companyName);
|
||||
return CreateResultFromCache(cachedMatch, companyName, startDate, endDate, jobTitle, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogDebug("Cached company {CachedName} was incorporated after claimed start date, searching for alternatives", cachedMatch.CompanyName);
|
||||
}
|
||||
}
|
||||
|
||||
// Search Companies House
|
||||
|
||||
Reference in New Issue
Block a user