Skip to content

Commit

Permalink
get all tasks seems to respond everything if page=0 so i revert the w…
Browse files Browse the repository at this point in the history
…ork.
  • Loading branch information
Heiss committed Aug 9, 2024
1 parent a918fb3 commit 4cf8876
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/processing/automaton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Automaton {
new GetTasks(app, plugin, processor),
new RemoveTasks(app, plugin),
new SyncLabels(app, plugin),
new UpdateTasks(app, plugin, processor),
new CreateTasks(app, plugin, processor),
new UpdateTasks(app, plugin, processor),
];

this.status = AutomatonStatus.READY;
Expand Down
3 changes: 2 additions & 1 deletion src/processing/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Processor {
if (file === null) {
return;
}
if (this.plugin.settings.debugging) console.log("Processor: Save to vault", task, newTask);
await this.app.vault.process(file, data => {
let content;
if (this.plugin.settings.appendMode) {
Expand All @@ -92,9 +93,9 @@ class Processor {
}
content = lines.join("\n");
}
this.plugin.cache.update(task);
return content;
});
this.plugin.cache.update(task);
}

getTaskContent(task: PluginTask): string {
Expand Down
29 changes: 2 additions & 27 deletions src/vikunja/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,8 @@ class Tasks implements VikunjaAPI {
}

async getAllTasks(): Promise<ModelsTask[]> {
const gen = function* () {
let page = 0;
while (true) {
yield page++;
}
}

const arrayRange = (start: number, stop: number, step: number) =>
Array.from(
{length: (stop - start) / step + 1},
(value, index) => start + index * step
);

const tasks: ModelsTask[] = [];
let lastResponse: ModelsTask[] = [];
const number_gen = gen();
do {
const current_page = number_gen.next().value;
const page_array = arrayRange(current_page * 5, current_page * 5 + 4, 1);
if (this.plugin.settings.debugging) console.log("TasksApi: Getting tasks for page", current_page, page_array);
const response = await Promise.all(page_array.map(page => this.getTasksForPage(page)));
lastResponse = response.flat();
if (this.plugin.settings.debugging) console.log("TasksApi: Got tasks from Vikunja", lastResponse);
tasks.push(...lastResponse);
} while (lastResponse.length > 0);

return tasks;
const params: TasksAllGetRequest = {page: 0};
return await this.tasksApi.tasksAllGet(params);
}

async getTasksForPage(page: number): Promise<ModelsTask[]> {
Expand Down

0 comments on commit 4cf8876

Please sign in to comment.