diff --git a/src/indexer/database.ts b/src/indexer/database.ts index f2dfd73adfc7909bb204a3d996ecd4182f40d0e1..468a0f972828fa4a565f1c8e865974dbb3f20230 100644 --- a/src/indexer/database.ts +++ b/src/indexer/database.ts @@ -71,23 +71,24 @@ export async function setLatestIndexedCID(cid: CID) { } // cesium plus profile query and param builder -// completely overwrites previous data +// completely overwrites previous data if new timestamp is higher const cesiumPlusProfile: QueryBuilder = { query: `INSERT INTO profiles(index_request_cid, time, pubkey, data_cid, title, description, avatar, geoloc, city, socials) VALUES ($1, $2, $3, $4, $5, $6, $7, point($8, $9), $10, $11) ON CONFLICT (pubkey) DO UPDATE SET - index_request_cid = EXCLUDED.index_request_cid, - time = EXCLUDED.time, - pubkey = EXCLUDED.pubkey, - data_cid = EXCLUDED.data_cid, - title = EXCLUDED.title, - description = EXCLUDED.description, - avatar = EXCLUDED.avatar, - geoloc = EXCLUDED.geoloc, - city = EXCLUDED.city, - socials = EXCLUDED.socials; + index_request_cid = EXCLUDED.index_request_cid, + time = EXCLUDED.time, + pubkey = EXCLUDED.pubkey, + data_cid = EXCLUDED.data_cid, + title = EXCLUDED.title, + description = EXCLUDED.description, + avatar = EXCLUDED.avatar, + geoloc = EXCLUDED.geoloc, + city = EXCLUDED.city, + socials = EXCLUDED.socials; + WHERE EXCLUDED.time > profiles.time; `, dataGetter: defaultDataGetter, dataTransform: defaultDataTransform,