-
Notifications
You must be signed in to change notification settings - Fork 13
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
Prevent processing of duplicate parts #4
Comments
Thanks, we are looking in this |
Hey @AndreasGassmann how are you trying to get the progress? The library ignores the duplicate parts but keeps track of every processed part, even if duplicate. There are 2 functions you can use to get a report on progress: The My guess is that you're using |
I'm assuming you are keeping track of every processed part to estimate the completion. But shouldn't duplicates on the "page" level be ignored? So if you scan ur:bytes/1-5/... 20 times, shouldn't it be ignored after being processed once?
This was the reason why we ended up using I understand that It's not really an issue for us because it can easily be handled, but I feel like it's something other people might run into as well. |
The "keeping track" part is just a number that gets incremented every time a part is received. That doesn't mean that it's duplicated internally.
In my opinion,
Can you elaborate a bit on the way you're handling it? From what I understand, if you're ignoring the duplicate parts, you should be getting the same values as |
We match the whole string we scan, something like this: // const qrs = new Set()
// const qr: string = 'ur:bytes/1-10/...'
if (!qrs.has(qr)) {
ur.receive(qr)
qrs.add(qr)
} |
Are you getting the progress by doing something like this? // from the `ur:bytes/1-10/...` you can get that
const expectedLength = 10
const progress = qrs.size() / expectedLength This will exactly match the result of If you're using something like the snippet above, you can also end up overshooting if the scanning device randomly misses parts and ends up having to scan the mixed parts ( The way I've handled that in an app is by doing: ur.receivePart(data);
// it's complete, parse data, use them, stop scanner
if (ur.isComplete()) {}
// update progress
setProgress(urDecoder.getProgress()); |
Sorry if I was unclear, but we use Assuming we have a payload that will result in 2 UR parts:
If those are displayed 1 second each, but the scanner scans 5 times per second, it will register some of them multiple times.
If I call |
That is the expected result of
You can see here that if the fragment/part already exists, it will ignore it, so only unique parts are saved. There's no need to store and compare raw strings. processSimplePart(): {
if (this.receivedPartIndexes.includes(fragmentIndex)) {
return;
}
this.simpleParts.push({ key: part.indexes, value: part });
this.receivedPartIndexes.push(fragmentIndex);
...
} The So, you can safely call |
When the same part is "received" multiple times, this library will process each of the requests. This will result in the progress being higher than it should be. I now catch this outside the library, but maybe it would make sense to include it (basically just ignoring duplicates).
The text was updated successfully, but these errors were encountered: