acebase icon indicating copy to clipboard operation
acebase copied to clipboard

Sorting is always ascending when using indexes and take()

Open Mitsichury opened this issue 2 years ago • 3 comments

Hi :)

I've been through a weird behaviour when trying to sort data. Here a TU that reproduce the issue. Could you fix it please or tell me what do I do wrong please ? Thank you very much.

` /// const { DataReference, ObjectCollection } = require("acebase-core"); const { AceBase } = require(".."); const { createTempDB } = require("./tempdb");

describe("Query", () => { /** @type {AceBase} / let db; /* @type {{(): Promise}} */ let removeDB;

/** @type {DataReference} */
let moviesRef;

afterAll(async () => {
    await removeDB();
});

beforeAll(async () => {
    ({ db, removeDB } = await createTempDB());
    db.indexes.create(`movies`, "name");
    db.indexes.create(`movies`, "amount");
    moviesRef = db.ref("movies");
    const entry1 = {
        id: "id1",
        name: "name",
        amount: 1,
    };
    const entry2 = {
        id: "id2",
        name: "another",
        amount: 10,
    };
    const entry3 = {
        id: "id3",
        name: "name",
        amount: 100,
    };

    const movies = [entry1, entry2, entry3];
    await moviesRef.set(ObjectCollection.from(movies));
});

it("error with indexes, order and take", async () => {
    const errors = await getDataBy(["name"]);
    expect(errors.getValues().map(({ id }) => id)).toEqual(["id3", "id1"]);
});

async function getDataBy(requestFilter) {
    const query = moviesRef.query();
    query.filter("name", "in", requestFilter);
    query.sort("amount", false);
    return await query.take(20).get();
}

}); `

Mitsichury avatar Jul 02 '22 16:07 Mitsichury

Thanks for reporting, I'll take a look!

appy-one avatar Jul 04 '22 18:07 appy-one

I found the issue, working on a fix

appy-one avatar Jul 05 '22 19:07 appy-one

Super fast, thank you very much ! :D

Mitsichury avatar Jul 06 '22 19:07 Mitsichury

I published the fix in v1.22.0!

Spread the word contribute Sponsor AceBase

appy-one avatar Aug 19 '22 19:08 appy-one