Is there some reason that documents from one colle...
# community-help
p
Is there some reason that documents from one collection might be appearing in another collection? I am using the javascript library and I think I've been very careful about keeping the collections separate, but searches on one collection are showing me documents that I can tell from the data should be in a different collection
k
I think this might be because of the
client
object being shared across different parts of the code at the same time. Can you try instantiating separate client objects?
p
Interesting thanks Yes I can, would I want to scope the client per collection?
k
Yes we can start with that to see if the problem gets resolved. To be clear you will face this problem only when two async functions end up sharing the same client which accesses two different collections.
p
I am doing a huge amount of async work, and they all shared the same client. I tried creating a client cache per collection name (actually alias name if that makes a difference) but I am still having the same problem
k
Would it be possible to create a standalone example that showcases the issue?
p
I think so, I'm not doing anything too crazy, just importing a bunch of things, then multi searching on them
k
Ok if you can share a snippet I can run and debug what's happening.
p
Okay, on a little more investigation it may be related to using import on the javascript client, replacing it with, roughly Promise.all(collection.upsert) seems to have solved my problem on a quick investigation
k
Oh I see, can you post the before/after of that segment?
p
Sure the before is just in comment here:
Copy code
/*if (threads.length > 0) {
  await collection.documents().import(searchThreads, { action: "upsert" })
}*/
await Promise.all(searchThreads.map(c => collection.documents().upsert(c)))
I'll do a little more testing tomorrow and see if I can see what actually make a difference
Nevermind, on a second run the problem is still there using upsert, I think I just got a random successful query
k
Ok, we can take a look at a reproduceable snippet.
p
Okay great thanks, I'll put something together tomorrow
👍 1
k
I've identified a potential race condition that could happen locally (but super rare when you connect to Typesense on another host) that I've fixed in
0.24.0.rc20
build. Could you please test against that to see if it helps? I've published to Docker.
👍 1
p
Tried from scratch 3 times in a row and didn't see the error, before that it was happening consistently at least 1 out of 2 times
Thank you! Really appreciate it
Wasn't able to reproduce yet in a new repo, my production app is pretty complicated
k
Thanks for confirming!