Skip to content

Commit

Permalink
fix: trim titles and skip empty entries
Browse files Browse the repository at this point in the history
This cleans up the visual output (no trailing whitespaces).

I noticed that a trailing `null` entry was coming out from the CSV
parsing of the SQLite dump. This was because we didn't have the
`skipEmptyLines` to avoid `null` records from showing up.

fix:
  • Loading branch information
kevinjalbert committed May 23, 2021
1 parent 4527594 commit d9e9331
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function parseCSV<T>(csv: Buffer[]): T[] {
dynamicTyping: true,
header: true,
newline: "\n",
skipEmptyLines: true,
}).data;
}

Expand Down
7 changes: 5 additions & 2 deletions src/things.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ export function buildTasksFromSQLRecords(
const tasks: Record<string, ITask> = {};
taskRecords.forEach(({ tag, ...task }) => {
const id = task.uuid;

if (tasks[id]) {
tasks[id].tags.push(tag);
} else {
tasks[id] = {
...task,
title: task.title.trimEnd(),
subtasks: [],
tags: [tag],
};
Expand All @@ -65,7 +67,7 @@ export function buildTasksFromSQLRecords(
const task = tasks[taskId];
const subtask = {
completed: !!stopDate,
title,
title: title.trimEnd(),
};

// checklist item might be completed before task
Expand Down Expand Up @@ -100,7 +102,7 @@ async function getTasksFromThingsDb(
ON TMTaskTag.tasks = TMTask.uuid
LEFT JOIN TMTag
ON TMTag.uuid = TMTaskTag.tags
LEFT JOIN TMArea
LEFT JOIN TMArea
ON TMTask.area = TMArea.uuid
WHERE
TMTask.trashed = 0
Expand All @@ -126,6 +128,7 @@ async function getChecklistItemsThingsDb(
TMChecklistItem
WHERE
stopDate > ${latestSyncTime}
AND title IS NOT ""
ORDER BY
stopDate
LIMIT ${TASK_FETCH_LIMIT}
Expand Down

0 comments on commit d9e9331

Please sign in to comment.