client.subscribe('databases.default.collections.rss_articles.documents.*.delete', callback)
Would not return anything, thus client.subscribe('databases.default.collections.rss_articles.documents, callback); would return a ton of information, but i want to filter for only deleted in this occasion
At the moment I do js
subscribeArticles: async (callback) => { client.subscribe('databases.default.collections.rss_articles.documents', callback);
}, then ```js
AppwriteService.subscribeArticles(onArticleChange);
function onArticleChange(response) { const { events, payload } = response; if (events.includes("databases.default.collections.rss_articles.documents..delete")) { $posts = $posts.filter(post => post.$id !== payload.$id); } else if (events.includes("databases..collections.rss_articles.documents.*.create")) { $posts = [response.payload, ...$posts] } }``` What i have noticed is, if i add 20 articles really fast, it would skip some article add updates, any ideas?
yes, because databases.default.collections.rss_articles.documents.*.delete is not a channel. the supported channels are: https://appwrite.io/docs/realtime#channels
this is probably due to a concurrency problem. This callback is probably executing at the same time or so and they're overwriting each other
const updateQueue = [];
function processQueue() {
while (updateQueue.length > 0) {
const { events, payload } = updateQueue.shift();
if (events.includes("databases.default.collections.rss_articles.documents.*.delete")) {
$posts = $posts.filter(post => post.$id !== payload.$id);
} else if (events.includes("databases.*.collections.rss_articles.documents.*.create")) {
const existingPostIndex = $posts.findIndex(post => post.$id === payload.$id);
if (existingPostIndex === -1) {
$posts = [payload, ...$posts];
} else {
$posts[existingPostIndex] = payload;
}
}
}
}
function onArticleChange(response) {
updateQueue.push(response);
processQueue();
}
``` tried to come up with a queue solution, but got the same result. Got to think here..
i think a lot of state management solutions make this easier...
could you elaborate on that i don't understand? you mean like store? $posts is a store already, if you mean by that
what framework are you using?
sveltekit
hmm, let me run some tests, it seems that it fixed the problem, i guess i didn't save the file before hand
yeah it added 101 posts with no problem now
@Steven i can subscribe to only one realtime stream connection right? I need to break the connection once i go to another page, if I want to subscribe to another one?
up to you, though it would make sense not to subscribe to a channel you don't care about anymore
Seems like a success for today
got to figure out how to assign users to the posts from which are the feeds and should be golden
i've updated the code, so it would not add duplicate keys, which could result in error, maybe someone will benefit from it
[SOLVED] realtime *.delete not working as expected.
How did you have made this video? š¤©
Screen Studio
Looks great, cogratulations
thanks man, i thought deploying the costum functions would be much harder
atleast my previous experience was
Me too first time, then I found It was really easy to work with š
Recommended threads
- How to Display File in Web?
I'm trying to use Appwrite's Storage to store images and display them in my app, however when I use the `getFileView`, `getFileDownload` or `getFilePreview` met...
- Project Paused Despite Daily Active Usag...
I noticed that my project was automatically **paused**, even though it is actively being used. The project is an **attendance application** that is used daily b...
- Sudden CORS Errors - Domain hasn't Chang...
I have an Appwrite project with two web apps configured, the first one has the hostname `*` and the second one I just added to test if it could fix the issue wi...