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
- self-hosted auth: /v1/account 404 on saf...
Project created in React/Next.js, Appwrite version 1.6.0. Authentication works in all browsers except Safari (ios), where an attempt to connect to {endpoint}/v1...
- delete document problems
i don't know what's going on but i get an attribute "tournamentid" not found in the collection when i try to delet the document... but this is just the document...
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...