From e3eaa53a519429dd232ce5fb96449709f47b0add Mon Sep 17 00:00:00 2001 From: Benjamin Conn Date: Mon, 16 Oct 2023 14:18:24 -0400 Subject: [PATCH] fix conflict statement --- db/migrations/core/000112_contract_l1.up.sql | 3 ++- service/persist/postgres/contract_gallery.go | 6 ++---- service/recommend/userpref/personalize.go | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/db/migrations/core/000112_contract_l1.up.sql b/db/migrations/core/000112_contract_l1.up.sql index 4a9643da8..cf5d6fa58 100644 --- a/db/migrations/core/000112_contract_l1.up.sql +++ b/db/migrations/core/000112_contract_l1.up.sql @@ -3,7 +3,8 @@ update contracts set l1_chain = 0; alter table contracts alter column l1_chain set not null; update contracts set l1_chain = 4 where chain = 4; create index contracts_l1_chain_idx on contracts (address,chain,l1_chain) where deleted = false; -create unique index contracts_l1_chain_unique_idx on contracts (address,l1_chain) where deleted = false; +create unique index contracts_l1_chain_unique_idx on contracts (l1_chain,address) where parent_id is null; +create unique index contracts_l1_chain_parent_unique_idx on contracts (l1_chain,parent_id,address) where parent_id is not null; drop view if exists contract_creators; diff --git a/service/persist/postgres/contract_gallery.go b/service/persist/postgres/contract_gallery.go index d60d2656c..2b3acf4ac 100644 --- a/service/persist/postgres/contract_gallery.go +++ b/service/persist/postgres/contract_gallery.go @@ -46,16 +46,14 @@ func NewContractGalleryRepository(db *sql.DB, queries *db.Queries) *ContractGall upsertByAddressStmt, err := db.PrepareContext(ctx, ` insert into contracts (id,version,address,symbol,name,owner_address,chain,l1_chain,description,profile_image_url) values ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) - on conflict (address,chain) where parent_id is null do update set + on conflict (address,l1_chain) where parent_id is null do update set version = $2, address = $3, symbol = coalesce(nullif(contracts.symbol, ''), nullif($4, '')), name = coalesce(nullif(contracts.name, ''), nullif($5, '')), description = coalesce(nullif(contracts.description, ''), nullif($9, '')), profile_image_url = coalesce(nullif(contracts.profile_image_url, ''), nullif($10, '')), - owner_address = case when nullif(contracts.owner_address, '') is null then $6 else contracts.owner_address end, - chain = $7, - l1_chain = $8 + owner_address = case when nullif(contracts.owner_address, '') is null then $6 else contracts.owner_address end returning id; `) checkNoErr(err) diff --git a/service/recommend/userpref/personalize.go b/service/recommend/userpref/personalize.go index 52f79a070..91a21fd92 100644 --- a/service/recommend/userpref/personalize.go +++ b/service/recommend/userpref/personalize.go @@ -266,7 +266,7 @@ func (p *Personalization) update(ctx context.Context) { if p.pM == nil { logger.For(ctx).Infof("no data loaded, reading from cache") - p.readCache(ctx) + // p.readCache(ctx) return }