From b5b1a92697ddfbf9898fa2f9395581a1c5cbc8ec Mon Sep 17 00:00:00 2001 From: caffix Date: Tue, 13 Aug 2024 23:45:44 -0400 Subject: [PATCH] game changing optimization for FindAssetByContent --- repository/sql.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/repository/sql.go b/repository/sql.go index ccc297e..1c7eb24 100644 --- a/repository/sql.go +++ b/repository/sql.go @@ -214,9 +214,9 @@ func (sql *sqlRepository) FindAssetByContent(assetData oam.Asset, since time.Tim var assets []Asset var result *gorm.DB if since.IsZero() { - result = sql.db.Find(&assets, jsonQuery) + result = sql.db.Where("type = ?", asset.Type).Find(&assets, jsonQuery) } else { - result = sql.db.Where("last_seen > ?", since).Find(&assets, jsonQuery) + result = sql.db.Where("type = ? AND last_seen > ?", asset.Type, since).Find(&assets, jsonQuery) } if result.Error != nil { return []*types.Asset{}, result.Error @@ -361,7 +361,7 @@ func (sql *sqlRepository) isDuplicateRelation(source *types.Asset, relation stri _ = sql.relationSeen(out) rel, err = sql.relationById(out.ID) if err != nil { - log.Println("[ERROR] failed to when re-retrieving relation", err) + log.Println("[ERROR] failed when re-retrieving relation", err) return nil, false } dup = true