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

query returning different results each time #15

Closed
sallespro opened this issue Jul 24, 2014 · 4 comments
Closed

query returning different results each time #15

sallespro opened this issue Jul 24, 2014 · 4 comments

Comments

@sallespro
Copy link

hi, just wanted to check wether i am doing something wrong to get such "unstable" results.

i have played with dexie on top of Chrome and FFOS, as well as the webview on Android 4.1.2 up to 4.4 Kitkat, and on all of them the results of a query like below was different each time or so.

         db.phones.where('name').startsWithIgnoreCase('moto'));

it seems to increase the occurrence, and even not responding at all when the OR clause is included in the query chain.

            db.phones.where('name').startsWithIgnoreCase('moto')).or('age').below('10'));

the only creepy thing i have done was creating a lot of indexes...(14) too much ?

        var dbi = new Dexie("MyDB");
        dbi.version(1).stores({
            phones: "++id, additionalFeatures, android, availability, battery, camera, connectivity, description, display, hardware, id, images, name, sizeAndWeight, storage"
        });
@dfahlander
Copy link
Collaborator

Don't think the number of indexes are any problems. I'll do a unit test to
reproduce it next week (holiday right now). Did you miss to index 'age' or
is it just a typo? Do you get any error if adding a final .catch() at the
end?
Den 24 jul 2014 17:35 skrev "salles" notifications@github.com:

hi, just wanted to check wether i am doing something wrong to get such
"unstable" results.

i have played with dexie on top of Chrome and FFOS, as well as the webview
on Android 4.1.2 up to 4.4 Kitkat, and on all of them the results of a
query like below

     db.phones.where('name').startsWithIgnoreCase('moto'));

it seems to increase the occurrence, and even not responding at all when
the OR clause is included in the query chain.

        db.phones.where('name').startsWithIgnoreCase('moto')).or('age').below('10'));

the only creepy thing i have done was creating a lot of indexes...(14) too
much ?

    var dbi = new Dexie("MyDB");
    dbi.version(1).stores({
        phones: "++id, additionalFeatures, android, availability, battery, camera, connectivity, description, display, hardware, id, images, name, sizeAndWeight, storage"
    });


Reply to this email directly or view it on GitHub
#15.

@dfahlander
Copy link
Collaborator

Could you describe how it increases the occurrence? Are you using toArray () or each() to get the results? The or method may (and usually does) produce the results in random order, but should never give different results.

If you have a chance to provide a sample code and data to reproduce it that would be very helpful.

Thanks,
David

@dfahlander
Copy link
Collaborator

I could not reproduce the error. I replaced "age" with "id" to make the query on a registered index. Otherwise the query would fail each time with "NotFoundError" becuase the index "age" wasn't found. When using an existing index I always get the same results. I've tested in Chrome 36.0.1985.125, Opera 22.0.1471.70, Firefox 30 and IE11.

I belive your error could be due to an error from an earlier write operaion you've made and did not wait for to finish. Check what happens if you catch your write operations performed prior to executing your or() query. When you start your query using the or() operation, the earlier write operation has not yet failed. When it fails, one of the or() parts will fail with the real error and the other with an "AbortError". Which one that gets the first error may vary. If you catch your or() operation you may get the actual error, or the AbortError. But the best thing is to catch the earlier write operations to see where they fail. These are my guesses and only a therory since I could not reproduce the error.

In my test, I could execute 10 simiultanous queries with the or() method applied, as well as executing the in sequence. Each time I run the unit test I get the same results. Here's the code:

asyncTest("or-issue#15-test", function () {
    var db = new Dexie("MyDB_issue15");
    db.version(1).stores({
        phones: "++id, additionalFeatures, android, availability, battery, camera, connectivity, description, display, hardware, id, images, name, sizeAndWeight, storage"
    });
    db.on('populate', function () {
        ok(true, "on(populate) called");
        for (var i = 0; i < 100; ++i) {
            db.phones.add({ name: "Name" + randomString(16), additionalFeatures: [randomString(10)], android: 1, availability: 0, battery: 1, camera: 1 });
        }

        function randomString(count) {
            var ms = [];
            for (var i = 0; i < count; ++i) {
                ms.push(String.fromCharCode(32 + Math.floor(Math.random() * 96)));
            }
            return ms.join('');
        }
    });

    db.open().catch(function (err) {
        ok(false, "DB ERROR: " + err);
    });


    var numRuns = 10;

    for (var i = 0; i < numRuns; ++i) {

        db.phones.where("name").startsWithIgnoreCase("name").or("id").below(50).toArray(function (a) {

            equal(a.length, 100, "Found 100 phones");

        }).catch(function (err) {

            ok(false, "error:" + err);

        }).finally(function () {
            if (--numRuns == 0) {
                // All test runs finished. Delete DB and exit unit test.
                db.delete();
                start();
            }
        });
    }

});

If you have some code to reproduce the error, your welcome and I will debug it for you, otherwise I will close this issue within some days.

Thanks,
David

@sallespro
Copy link
Author

hi, thanks for your detailed analysis and commitment to help !

i have indeed missed the 'age' indexing which might have been the source of the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants