Always create a common tracker pattern during mapping
When neither pattern nor domain matching finds an existing common tracker pattern, upsert one with no third party association and a lower confidence (0.5) so every seen pattern is cataloged. Also fix table name in LoadByOrganizationIDAndCommonThirdPartyID (vendors -> third_parties). Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -85,6 +85,10 @@ func (h *trackerMappingHandler) Process(ctx context.Context, tp coredata.Tracker
|
|||||||
commonPatternID, thirdPartyID = h.matchByDomain(ctx, tx, tp)
|
commonPatternID, thirdPartyID = h.matchByDomain(ctx, tx, tp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if commonPatternID == nil {
|
||||||
|
commonPatternID = h.createUnmatchedPattern(ctx, tx, tp)
|
||||||
|
}
|
||||||
|
|
||||||
if commonPatternID != nil || thirdPartyID != nil {
|
if commonPatternID != nil || thirdPartyID != nil {
|
||||||
if err := tp.UpdateMapping(ctx, tx, commonPatternID, thirdPartyID); err != nil {
|
if err := tp.UpdateMapping(ctx, tx, commonPatternID, thirdPartyID); err != nil {
|
||||||
return fmt.Errorf("cannot update tracker pattern mapping: %w", err)
|
return fmt.Errorf("cannot update tracker pattern mapping: %w", err)
|
||||||
@@ -179,6 +183,37 @@ func (h *trackerMappingHandler) matchByDomain(
|
|||||||
return &commonPattern.ID, thirdPartyID
|
return &commonPattern.ID, thirdPartyID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *trackerMappingHandler) createUnmatchedPattern(
|
||||||
|
ctx context.Context,
|
||||||
|
tx pg.Tx,
|
||||||
|
tp coredata.TrackerPattern,
|
||||||
|
) *gid.GID {
|
||||||
|
now := time.Now()
|
||||||
|
commonPattern := coredata.CommonTrackerPattern{
|
||||||
|
ID: gid.New(gid.NilTenant, coredata.CommonTrackerPatternEntityType),
|
||||||
|
TrackerType: tp.TrackerType,
|
||||||
|
Pattern: tp.Pattern,
|
||||||
|
MatchType: tp.MatchType,
|
||||||
|
Description: tp.Description,
|
||||||
|
MaxAgeSeconds: tp.MaxAgeSeconds,
|
||||||
|
Confidence: 0.5,
|
||||||
|
CreatedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
actualID, _, err := commonPattern.Upsert(ctx, tx)
|
||||||
|
if err != nil {
|
||||||
|
h.logger.ErrorCtx(
|
||||||
|
ctx,
|
||||||
|
"cannot upsert common tracker pattern for unmatched pattern",
|
||||||
|
log.Error(err),
|
||||||
|
)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &actualID
|
||||||
|
}
|
||||||
|
|
||||||
func (h *trackerMappingHandler) resolveThirdParty(
|
func (h *trackerMappingHandler) resolveThirdParty(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Querier,
|
conn pg.Querier,
|
||||||
|
|||||||
@@ -1352,7 +1352,7 @@ SELECT
|
|||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
FROM
|
FROM
|
||||||
vendors
|
third_parties
|
||||||
WHERE
|
WHERE
|
||||||
%s
|
%s
|
||||||
AND organization_id = @organization_id
|
AND organization_id = @organization_id
|
||||||
|
|||||||
Reference in New Issue
Block a user