Skip to content

Commit

Permalink
Save all fields for keychains and adjust the order of the keychains f…
Browse files Browse the repository at this point in the history
…ield.Remove the logic: && item.defindex !== 1355.
  • Loading branch information
wangxingzhen committed Oct 19, 2024
1 parent 85c5a93 commit 8d9d682
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions lib/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,9 @@ class Postgres {
buf.writeFloatBE(item.floatvalue, 0);
item.paintwear = buf.readInt32BE(0);

if (item.floatvalue <= 0 && item.defindex !== 507 && item.defindex !== 1355) {
// Only insert weapons and keychains, naive check
// Special case for the 0 float Karambit and keychains.
// The keychains has a unique pattern
if (item.floatvalue <= 0 && item.defindex !== 507) {
// Only insert weapons, naive check
// Special case for the 0 float Karambit
continue;
}

Expand Down Expand Up @@ -253,11 +252,17 @@ class Postgres {

const keychains = item.keychains.length > 0 ? item.keychains.map((s) => {
const res = {s: s.slot, i: s.sticker_id};
if (s.pattern) {
res.pattern = s.pattern;
if (s.wear) {
res.w = s.wear;
}
if (s.scale) {
res.scale = s.scale;
}
if (s.rotation) {
res.r = s.rotation;
}
if (s.name) {
res.name = s.name;
if (s.tint_id) {
res.tint_id = s.tint_id;
}
if (s.offset_x) {
res.x = s.offset_x;
Expand All @@ -268,6 +273,9 @@ class Postgres {
if (s.offset_z) {
res.z = s.offset_z;
}
if (s.pattern) {
res.pattern = s.pattern;
}
return res;
}) : null;

Expand All @@ -288,7 +296,7 @@ class Postgres {
}

values.push([ms, item.a, item.d, item.paintseed, item.paintwear, item.defindex, item.paintindex, isStattrak,
isSouvenir, props, JSON.stringify(stickers), item.rarity, price, JSON.stringify(keychains)]);
isSouvenir, props, JSON.stringify(stickers), JSON.stringify(keychains), item.rarity, price]);
}

if (values.length === 0) {
Expand All @@ -308,13 +316,13 @@ class Postgres {
const values = [];
let i = 1;

// Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, now(), $12, NULL, $13)
// Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, $12::jsonb, now(), $13, NULL, $14)
for (let c = 0; c < itemCount; c++) {
values.push(`($${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}::jsonb, now(), $${i++}, NULL, $${i++}, $${i++}::jsonb)`);
values.push(`($${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}::jsonb, $${i++}::jsonb, now(), $${i++}, NULL, $${i++})`);
}

return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, updated, rarity, floatid, price, keychains)
VALUES ${values.join(', ')} ON CONFLICT(defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=excluded.ms, a=excluded.a, d=excluded.d, stickers=excluded.stickers, updated=now(), keychains=excluded.keychains`;
return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, keychains, updated, rarity, floatid, price)
VALUES ${values.join(', ')} ON CONFLICT(defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=excluded.ms, a=excluded.a, d=excluded.d, stickers=excluded.stickers, keychains=excluded.keychains, updated=now()`;
}

updateItemPrice(assetId, price) {
Expand Down Expand Up @@ -385,11 +393,14 @@ class Postgres {
return {
sticker_id: s.i,
slot: s.s,
pattern: s.pattern,
name: s.name,
wear: s.w,
scale: s.scale,
rotation: s.r,
tint_id: s.tint_id,
offset_x: s.x,
offset_y: s.y,
offset_z: s.z,
pattern: s.pattern,
}
});

Expand Down

0 comments on commit 8d9d682

Please sign in to comment.