Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library is crashing while firing it's change event on query #61

Closed
directtosumit opened this issue Jan 25, 2022 · 6 comments
Closed

Library is crashing while firing it's change event on query #61

directtosumit opened this issue Jan 25, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@directtosumit
Copy link

I had set sort, filter and change listener at the node "/bpm";

function gotMatches(snaps) {
const data={};
snaps.forEach(snap => {
data[snap.key] = snap.val();
});
lis(data);
}
const valueChanged=() => {
db.get({include, exclude}).then(gotMatches).catch(err);
};
function matchAdded() {
valueChanged();
}
function matchChanged() {
valueChanged();
}
function matchRemoved() {
valueChanged();
}
db
.on('add', matchAdded)
.on('change', matchChanged)
.on('remove', matchRemoved);
valueChanged();

[database] Reading node "/bpm/kytk61qh001doazk0c46fvkr" from address 0,10
0|index | [database] Node "/bpm/kytk61qh001doazk0c46fvkr" being updated: adding 0 keys (), updating 1 keys ("value"), removing 0 keys ()
0|index | [database] Node "/bpm/kytk61qh001doazk0c46fvkr" saved at address 0,10 - 1 addresses, 50 bytes written in 1 chunk(s)
0|index | TypeError: Cannot convert undefined or null to object
0|index | at Function.keys ()
0|index | at Object.childChangedCallback [as callback] (/Local Tcp Server/node_modules/acebase/src/api-local.js:728:60)
0|index | at /Local Tcp Server/node_modules/acebase/src/storage.js:494:25
0|index | at Array.forEach ()
0|index | at Object.trigger (/Local Tcp Server/node_modules/acebase/src/storage.js:493:18)
0|index | at /Local Tcp Server/node_modules/acebase/src/storage.js:1066:51
0|index | at Array.forEach ()
0|index | at triggerAllEvents (/Local Tcp Server/node_modules/acebase/src/storage.js:1012:14)
0|index | at processTicksAndRejections (node:internal/process/task_queues:78:11)
PM2 | App [index:0] exited with code [1] via signal [SIGINT]

@appy-one appy-one self-assigned this Jan 25, 2022
@appy-one
Copy link
Owner

Thanks for reporting, I'll take a look

@appy-one
Copy link
Owner

I managed to reproduce the error, looks like a bit of refactoring on my end is needed to fix it.

A very quick fix for you would be to edit line 866 in api-local.js, change 'notify_child_changed' to 'child_changed'. Make the same edit in line 715.

Let me know if that works for now.

@appy-one
Copy link
Owner

By the way, I see that you are manually refreshing the data in your code upon changes, but that is not necessary. The essence of a realtime query is that your query results are updated in realtime, so you don't have to execute the query again after changes. See the following example:

const fiveStarBooks = {}; // local query result set
const snaps = await db.query('books')
    .filter('rating', '==', 5)
    .on('add', match => {
        // add book to results
        fiveStarBooks[match.snapshot.key] = match.snapshot.val();
    })
    .on('change', match => {
        // update book details
        fiveStarBooks[match.snapshot.key] = match.snapshot.val();
    })
    .on('remove', match => {
        // remove book from results
        delete fiveStarBooks[match.ref.key];
    })
    .get();

// Add current query results to our local result set
snaps.forEach(snap => {
    fiveStarBooks[snap.key] = snap.val();
});

The add, change and remove callbacks update the local state without executing the query again

@directtosumit
Copy link
Author

directtosumit commented Jan 27, 2022 via email

@appy-one
Copy link
Owner

appy-one commented Feb 1, 2022

It's a little unclear to me why you would do your updates on a different target? The node you are updating has no effect on events firing, and has no effect on a realtime query either?

paradis-A added a commit to paradis-A/acebase that referenced this issue Feb 6, 2022
@appy-one appy-one added the bug Something isn't working label Feb 9, 2022
appy-one added a commit that referenced this issue Feb 18, 2022
@appy-one
Copy link
Owner

I just published acebase version 1.15.0, let me know if it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants