-
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
It is not clear what is the described issue and there are not enough details to understand what If you have custom hooks make sure to check if they modify the record fields somehow. |
Beta Was this translation helpful? Give feedback.
-
I`m not using any hooks, or modifications to pocketbase. async function updateProgress(pbid, data) {
try {
await pb.collection("users_stats_collect").update(pbid, data)
} catch (e) {
consoleDev('Error while upgrading progress');
consoleDev(JSON.stringify(e));
}
} EXPORT [
{
"id": "uaa5eiu5653gt3e",
"name": "users_stats_collect",
"type": "base",
"system": false,
"schema": [
{
"system": false,
"id": "mqmnn8nl",
"name": "_user",
"type": "relation",
"required": true,
"presentable": false,
"unique": false,
"options": {
"collectionId": "_pb_users_auth_",
"cascadeDelete": false,
"minSelect": null,
"maxSelect": 1,
"displayFields": [
"username"
]
}
},
{
"system": false,
"id": "tnopaoah",
"name": "platform",
"type": "select",
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSelect": 1,
"values": [
"rgc",
"lagabuse"
]
}
},
{
"system": false,
"id": "gzpmnyx9",
"name": "uid",
"type": "text",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": null,
"max": null,
"pattern": ""
}
},
{
"system": false,
"id": "mfzmbalw",
"name": "username",
"type": "text",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": null,
"max": null,
"pattern": ""
}
},
{
"system": false,
"id": "71vxr9vb",
"name": "security_token",
"type": "text",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": null,
"max": null,
"pattern": ""
}
},
{
"system": false,
"id": "rfqdax36",
"name": "pfp",
"type": "text",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": null,
"max": null,
"pattern": ""
}
},
{
"system": false,
"id": "rdop2hnu",
"name": "flag",
"type": "text",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": 2,
"max": 2,
"pattern": ""
}
},
{
"system": false,
"id": "pyhbg9fk",
"name": "lastgame",
"type": "json",
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSize": 2000000
}
},
{
"system": false,
"id": "nsa2h367",
"name": "collect",
"type": "json",
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSize": 2000000
}
},
{
"system": false,
"id": "udmpbrk3",
"name": "progress",
"type": "json",
"required": false,
"presentable": false,
"unique": false,
"options": {
"maxSize": 2000000
}
},
{
"system": false,
"id": "pnujltpn",
"name": "is_default",
"type": "bool",
"required": false,
"presentable": false,
"unique": false,
"options": {}
},
{
"system": false,
"id": "6qaimtcd",
"name": "status",
"type": "select",
"required": true,
"presentable": false,
"unique": false,
"options": {
"maxSelect": 1,
"values": [
"validating",
"validated",
"ready",
"collecting",
"done"
]
}
}
],
"indexes": [
"CREATE INDEX `_uaa5eiu5653gt3e_created_idx` ON `users_stats_collect` (`created`)"
],
"listRule": "@request.auth.id = _user.id",
"viewRule": "@request.auth.id = _user.id",
"createRule": "@request.auth.id = _user.id",
"updateRule": "@request.auth.id = _user.id",
"deleteRule": "@request.auth.id = _user.id",
"options": {}
}
] |
Beta Was this translation helpful? Give feedback.
-
Thankyou for your time. |
Beta Was this translation helpful? Give feedback.
-
I tried with this (which uses directly the pb instance), and it worked just fine.. fml. <!DOCTYPE html />
<html>
<head>
<meta charset="utf-8" />
<title>Test</title>
</head>
<body>
<script type="module">
import PocketBase from "https://cdn.jsdelivr.net/gh/pocketbase/js-sdk@master/dist/pocketbase.es.mjs"
const pb = new PocketBase("https://dmap.pockethost.io");
await pb.collection("users_stats_collect").subscribe("*", (e) => {
console.log(e);
})
const player = await pb.collection(`users_stats_collect`).create({
_user: `y7864qoau1wk25q`,
security_token: null,
status: 'validating'
})
await pb.collection(`users_stats_collect`).update(player.id, {
platform: 'rgc',
uid: '9999',
username: 'd1map.bloor',
security_token: null,
pfp: null,
flag: 'xx',
collect: {},
progress: {},
status: 'collecting'
})
for (let index = 0; index < 10; index++) {
// simulate 10 updates
await pb.collection("users_stats_collect").update(player.id, { status: 'collecting', progress: {dota: index * 10, dotadynamic: index * 10} })
}
// simulate finishing - status=done
await pb.collection("users_stats_collect").update(player.id, { status: 'done', lastgame: {dota: 3}, progress: {}})
</script>
</body>
</html> |
Beta Was this translation helpful? Give feedback.
-
FIXEDI was unknowingly applying transformation on the record, right inside the subscribe event loop. await $pb.collection('users_stats_collect').subscribe('*', (e) => {
console.log(e.record)
if (e.action == 'create'){
players.value.push(e.record)
}
if (e.action == 'update'){
players.value.forEach((p,i) => {
if (p.id == e.record.id){
// players.value[i] = e.record // BAAAAAAAAAAAD
players.value[i] = {...e.record} //GOOD
if (p.platform == 'rgc'){
players.value[i].lastgame = p?.lastgame?.dota || p?.lastgame?.dotadynamic
}
}
})
}
if (e.action == 'delete'){
players.value = players.value.filter(p => p.id != e.record.id)
}
})
``` |
Beta Was this translation helpful? Give feedback.
FIXED
I was unknowingly applying transformation on the record, right inside the subscribe event loop.
I commented the bad code.
The difficult debugging part was , that
console.log()
, even being before anything else, was returning the already transformed value. So it was sending me in tail chase mode.