@@ -46,14 +46,15 @@ class Postgres {
46
46
props integer NOT NULL,
47
47
stickers jsonb,
48
48
updated timestamp NOT NULL,
49
- PRIMARY KEY (a, ms, d)
49
+ rarity smallint NOT NULL,
50
+ PRIMARY KEY (a)
50
51
)` ) ;
51
52
52
53
await this . pool . query ( `CREATE INDEX IF NOT EXISTS i_stickers ON items USING gin (stickers jsonb_path_ops)
53
54
WHERE stickers IS NOT NULL` ) ;
54
55
await this . pool . query ( `CREATE INDEX IF NOT EXISTS i_paintwear ON items (paintwear)` ) ;
55
56
await this . pool . query ( `CREATE UNIQUE INDEX IF NOT EXISTS i_unique_item ON
56
- items (defindex, paintindex, paintseed, paintwear )` ) ;
57
+ items (defindex, paintindex, paintwear, paintseed )` ) ;
57
58
}
58
59
59
60
async insertItemData ( item ) {
@@ -104,12 +105,12 @@ class Postgres {
104
105
105
106
// We define unique items as those that have the same skin, wear, and paint seed
106
107
// Duped items will be represented as one item in this case
107
- // If the item already exists, update it's link properties and stickers, these are the only attributes
108
- // that can change
109
- await this . pool . query ( `INSERT INTO items VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, now())
110
- ON CONFLICT (paintwear, defindex, paintindex, paintseed) DO UPDATE SET ms=$12 , a=$13 , d=$14 , stickers=$15 ` ,
108
+ // If the item already exists, update it's link properties and stickers only if it is more recent
109
+ // (higher item id)
110
+ await this . pool . query ( `INSERT INTO items VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, now(), $12 )
111
+ ON CONFLICT (defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=$13 , a=$14 , d=$15 , stickers=$16, updated=now() WHERE items.a < excluded.a ` ,
111
112
[ sm , item . a , item . d , item . paintseed , item . paintwear , item . defindex , item . paintindex , isStattrak ,
112
- isSouvenir , props , JSON . stringify ( stickers ) , sm , item . a , item . d , JSON . stringify ( stickers ) ] ) ;
113
+ isSouvenir , props , JSON . stringify ( stickers ) , item . rarity , sm , item . a , item . d , JSON . stringify ( stickers ) ] ) ;
113
114
} catch ( e ) {
114
115
winston . warn ( e ) ;
115
116
}
0 commit comments