fix: ensure no duplicate results when checking for missing collectible/collection ids in the db

This commit is contained in:
Dario Gabriel Lipicar 2024-03-08 09:48:38 -03:00 committed by dlipicar
parent c3e7d3823f
commit fcde7ccafe
2 changed files with 14 additions and 2 deletions

View File

@ -203,6 +203,12 @@ func scanCollectiblesDataRow(row *sql.Row) (*thirdparty.CollectibleData, error)
func (o *CollectibleDataDB) GetIDsNotInDB(ids []thirdparty.CollectibleUniqueID) ([]thirdparty.CollectibleUniqueID, error) {
ret := make([]thirdparty.CollectibleUniqueID, 0, len(ids))
idMap := make(map[string]thirdparty.CollectibleUniqueID, len(ids))
// Ensure we don't have duplicates
for _, id := range ids {
idMap[id.HashKey()] = id
}
exists, err := o.db.Prepare(`SELECT EXISTS (
SELECT 1 FROM collectible_data_cache
@ -212,7 +218,7 @@ func (o *CollectibleDataDB) GetIDsNotInDB(ids []thirdparty.CollectibleUniqueID)
return nil, err
}
for _, id := range ids {
for _, id := range idMap {
row := exists.QueryRow(
id.ContractID.ChainID,
id.ContractID.Address,

View File

@ -180,6 +180,12 @@ func scanCollectionsDataRow(row *sql.Row) (*thirdparty.CollectionData, error) {
func (o *CollectionDataDB) GetIDsNotInDB(ids []thirdparty.ContractID) ([]thirdparty.ContractID, error) {
ret := make([]thirdparty.ContractID, 0, len(ids))
idMap := make(map[string]thirdparty.ContractID, len(ids))
// Ensure we don't have duplicates
for _, id := range ids {
idMap[id.HashKey()] = id
}
exists, err := o.db.Prepare(`SELECT EXISTS (
SELECT 1 FROM collection_data_cache
@ -189,7 +195,7 @@ func (o *CollectionDataDB) GetIDsNotInDB(ids []thirdparty.ContractID) ([]thirdpa
return nil, err
}
for _, id := range ids {
for _, id := range idMap {
row := exists.QueryRow(
id.ChainID,
id.Address,