Skip to content

Commit

Permalink
Merge pull request #1774 from meilisearch/feat/add-tasks-reverse
Browse files Browse the repository at this point in the history
Add reverse parameter for getTasks
  • Loading branch information
Strift authored Dec 4, 2024
2 parents 5ac68c1 + 38fe56f commit dfe5be8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,11 @@ export type TasksQuery = {
afterFinishedAt?: Date;
limit?: number;
from?: number;
/**
* If true, the tasks are returned in reverse order (requires Meilisearch
* 1.12.0 or later)
*/
reverse?: boolean;
};

export type CancelTasksQuery = Omit<TasksQuery, "limit" | "from"> & {};
Expand Down
44 changes: 44 additions & 0 deletions tests/__snapshots__/settings.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports[`Test on settings > Admin key: Get default settings of an index 1`] = `
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -19,6 +20,7 @@ exports[`Test on settings > Admin key: Get default settings of an index 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -55,6 +57,7 @@ exports[`Test on settings > Admin key: Get default settings of empty index with
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -67,6 +70,7 @@ exports[`Test on settings > Admin key: Get default settings of empty index with
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -103,6 +107,7 @@ exports[`Test on settings > Admin key: Reset embedders settings 1`] = `
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -115,6 +120,7 @@ exports[`Test on settings > Admin key: Reset embedders settings 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -151,6 +157,7 @@ exports[`Test on settings > Admin key: Reset settings 1`] = `
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -163,6 +170,7 @@ exports[`Test on settings > Admin key: Reset settings 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -199,6 +207,7 @@ exports[`Test on settings > Admin key: Reset settings of empty index 1`] = `
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -211,6 +220,7 @@ exports[`Test on settings > Admin key: Reset settings of empty index 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -256,6 +266,7 @@ exports[`Test on settings > Admin key: Update embedders settings 1`] = `
"source": "huggingFace",
},
},
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -268,6 +279,7 @@ exports[`Test on settings > Admin key: Update embedders settings 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -304,6 +316,7 @@ exports[`Test on settings > Admin key: Update searchableAttributes settings on e
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -316,6 +329,7 @@ exports[`Test on settings > Admin key: Update searchableAttributes settings on e
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -352,6 +366,7 @@ exports[`Test on settings > Admin key: Update searchableAttributes settings on e
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -364,6 +379,7 @@ exports[`Test on settings > Admin key: Update searchableAttributes settings on e
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -403,6 +419,7 @@ exports[`Test on settings > Admin key: Update settings 1`] = `
"title",
],
"distinctAttribute": "title",
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 50,
"sortFacetValuesBy": {
Expand All @@ -421,6 +438,7 @@ exports[`Test on settings > Admin key: Update settings 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byAttribute",
"rankingRules": [
"id:asc",
Expand Down Expand Up @@ -469,6 +487,7 @@ exports[`Test on settings > Admin key: Update settings on empty index with prima
"*",
],
"distinctAttribute": "title",
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -481,6 +500,7 @@ exports[`Test on settings > Admin key: Update settings on empty index with prima
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"title:asc",
Expand Down Expand Up @@ -515,6 +535,7 @@ exports[`Test on settings > Admin key: Update settings with all null values 1`]
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -527,6 +548,7 @@ exports[`Test on settings > Admin key: Update settings with all null values 1`]
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -563,6 +585,7 @@ exports[`Test on settings > Master key: Get default settings of an index 1`] = `
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -575,6 +598,7 @@ exports[`Test on settings > Master key: Get default settings of an index 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -611,6 +635,7 @@ exports[`Test on settings > Master key: Get default settings of empty index with
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -623,6 +648,7 @@ exports[`Test on settings > Master key: Get default settings of empty index with
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -659,6 +685,7 @@ exports[`Test on settings > Master key: Reset embedders settings 1`] = `
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -671,6 +698,7 @@ exports[`Test on settings > Master key: Reset embedders settings 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -707,6 +735,7 @@ exports[`Test on settings > Master key: Reset settings 1`] = `
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -719,6 +748,7 @@ exports[`Test on settings > Master key: Reset settings 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -755,6 +785,7 @@ exports[`Test on settings > Master key: Reset settings of empty index 1`] = `
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -767,6 +798,7 @@ exports[`Test on settings > Master key: Reset settings of empty index 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -812,6 +844,7 @@ exports[`Test on settings > Master key: Update embedders settings 1`] = `
"source": "huggingFace",
},
},
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -824,6 +857,7 @@ exports[`Test on settings > Master key: Update embedders settings 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -860,6 +894,7 @@ exports[`Test on settings > Master key: Update searchableAttributes settings on
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -872,6 +907,7 @@ exports[`Test on settings > Master key: Update searchableAttributes settings on
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -908,6 +944,7 @@ exports[`Test on settings > Master key: Update searchableAttributes settings on
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -920,6 +957,7 @@ exports[`Test on settings > Master key: Update searchableAttributes settings on
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down Expand Up @@ -959,6 +997,7 @@ exports[`Test on settings > Master key: Update settings 1`] = `
"title",
],
"distinctAttribute": "title",
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 50,
"sortFacetValuesBy": {
Expand All @@ -977,6 +1016,7 @@ exports[`Test on settings > Master key: Update settings 1`] = `
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byAttribute",
"rankingRules": [
"id:asc",
Expand Down Expand Up @@ -1025,6 +1065,7 @@ exports[`Test on settings > Master key: Update settings on empty index with prim
"*",
],
"distinctAttribute": "title",
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -1037,6 +1078,7 @@ exports[`Test on settings > Master key: Update settings on empty index with prim
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"title:asc",
Expand Down Expand Up @@ -1071,6 +1113,7 @@ exports[`Test on settings > Master key: Update settings with all null values 1`]
"*",
],
"distinctAttribute": null,
"facetSearch": true,
"faceting": {
"maxValuesPerFacet": 100,
"sortFacetValuesBy": {
Expand All @@ -1083,6 +1126,7 @@ exports[`Test on settings > Master key: Update settings with all null values 1`]
"pagination": {
"maxTotalHits": 1000,
},
"prefixSearch": "indexingTime",
"proximityPrecision": "byWord",
"rankingRules": [
"words",
Expand Down
26 changes: 26 additions & 0 deletions tests/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,32 @@ describe.each([{ permission: "Master" }, { permission: "Admin" }])(
);
});

test(`${permission} key: Get all tasks in reverse order`, async () => {
const currentTimeStamp = Date.now();
const currentTime = new Date(currentTimeStamp);

const client = await getClient(permission);
const taskA = await client.index(index.uid).addDocuments([{ id: 1 }]);
const taskB = await client.index(index.uid).addDocuments([{ id: 2 }]);

await client.waitForTask(taskA.taskUid);
await client.waitForTask(taskB.taskUid);

const tasks = await client.getTasks({ afterEnqueuedAt: currentTime });
const reversedTasks = await client.getTasks({
afterEnqueuedAt: currentTime,
reverse: true,
});
expect(tasks.results.map((t) => t.uid)).toEqual([
taskB.taskUid,
taskA.taskUid,
]);
expect(reversedTasks.results.map((t) => t.uid)).toEqual([
taskA.taskUid,
taskB.taskUid,
]);
});

// filters error code: INVALID_TASK_TYPES_FILTER
test(`${permission} key: Try to filter on task types with wrong type`, async () => {
const client = await getClient(permission);
Expand Down

0 comments on commit dfe5be8

Please sign in to comment.