diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml
index fd8b7208b..fc31b6b2f 100644
--- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml
+++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml
@@ -57,6 +57,7 @@
1
apiTokenId
+
1
@@ -125,518 +126,544 @@
1
attributeId
+
1
noteId
+
name
value
+
-
- name
-
-
+
value
+
-
+
attributeId
1
sqlite_autoindex_attributes_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
1
-
+
4
INTEGER|0s
1
-
+
5
TEXT|0s
-
+
6
INTEGER|0s
1
0
-
+
7
INTEGER|0s
1
0
-
+
8
TEXT|0s
1
-
+
9
TEXT|0s
1
-
+
10
TEXT|0s
1
""
-
+
1
branchId
+
1
-
+
noteId
parentNoteId
+
-
- noteId
-
-
+
parentNoteId
+
-
+
branchId
1
sqlite_autoindex_branches_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
NULL
-
+
3
TEXT|0s
1
""
-
+
4
TEXT|0s
1
-
+
1
noteId
+
1
-
+
noteId
1
sqlite_autoindex_note_contents_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
-
+
3
TEXT|0s
1
''
-
+
4
TEXT|0s
1
-
+
1
noteRevisionId
+
1
-
+
noteRevisionId
1
sqlite_autoindex_note_revision_contents_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
-
+
4
INT|0s
1
-
+
5
INT|0s
1
0
-
+
6
INT|0s
1
0
-
+
7
TEXT|0s
1
-
+
8
TEXT|0s
1
-
+
9
TEXT|0s
1
-
+
10
TEXT|0s
1
-
+
11
TEXT|0s
1
-
+
12
TEXT|0s
1
''
-
+
13
TEXT|0s
1
''
-
+
14
TEXT|0s
1
''
-
+
1
noteRevisionId
+
1
-
+
noteId
+
-
+
utcDateLastEdited
+
-
+
utcDateCreated
+
-
+
dateLastEdited
+
-
+
dateCreated
+
-
+
noteRevisionId
1
sqlite_autoindex_note_revisions_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
"note"
-
+
3
INT|0s
1
-
+
4
INT|0s
1
0
-
+
5
TEXT|0s
1
'text'
-
+
6
TEXT|0s
1
'text/html'
-
+
7
TEXT|0s
1
""
-
+
8
INT|0s
1
0
-
+
9
INT|0s
1
0
-
+
10
TEXT|0s
1
-
+
11
TEXT|0s
1
-
+
12
TEXT|0s
1
-
+
13
TEXT|0s
1
-
+
1
noteId
+
1
-
+
title
+
-
+
type
+
-
+
isDeleted
+
-
+
dateCreated
+
-
+
dateModified
+
-
+
utcDateCreated
+
-
+
utcDateModified
+
-
+
noteId
1
sqlite_autoindex_notes_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
-
+
3
INTEGER|0s
1
0
-
+
4
TEXT|0s
1
""
-
+
5
TEXT|0s
1
-
+
6
TEXT|0s
1
-
+
1
name
+
1
-
+
name
1
sqlite_autoindex_options_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
1
""
-
+
4
TEXT|0s
1
-
+
5
INT|0s
-
+
1
noteId
+
1
-
+
noteId
1
sqlite_autoindex_recent_notes_1
-
+
1
TEXT|0s
1
-
+
2
TEXT|0s
1
-
+
1
sourceId
+
1
-
+
+ utcDateCreated
+
+
+
sourceId
1
sqlite_autoindex_source_ids_1
-
+
1
text|0s
-
+
2
text|0s
-
+
3
text|0s
-
+
4
int|0s
-
+
5
text|0s
-
+
1
-
+
2
-
+
1
INTEGER|0s
1
1
-
+
2
TEXT|0s
1
-
+
3
TEXT|0s
1
-
+
4
TEXT|0s
1
-
+
5
TEXT|0s
1
-
+
entityName
entityId
+
1
-
+
utcSyncDate
+
-
+
id
1
diff --git a/db/migrations/0155__indexes.sql b/db/migrations/0155__indexes.sql
new file mode 100644
index 000000000..dd523a35a
--- /dev/null
+++ b/db/migrations/0155__indexes.sql
@@ -0,0 +1,5 @@
+DROP INDEX IF EXISTS IDX_attributes_name_index;
+DROP INDEX IF EXISTS IDX_branches_noteId;
+
+CREATE INDEX IDX_source_ids_utcDateCreated
+ on source_ids (utcDateCreated);
\ No newline at end of file
diff --git a/db/migrations/0155__remove_unnecessary_indexes.sql b/db/migrations/0155__remove_unnecessary_indexes.sql
deleted file mode 100644
index 44630a241..000000000
--- a/db/migrations/0155__remove_unnecessary_indexes.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-DROP INDEX IF EXISTS IDX_attributes_name_index;
-DROP INDEX IF EXISTS IDX_branches_noteId;
\ No newline at end of file
diff --git a/db/schema.sql b/db/schema.sql
index d58476055..66af0788c 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -9,6 +9,8 @@ CREATE TABLE IF NOT EXISTS "source_ids" (
`utcDateCreated` TEXT NOT NULL,
PRIMARY KEY(`sourceId`)
);
+CREATE INDEX IDX_source_ids_utcDateCreated
+ on source_ids (utcDateCreated);
CREATE TABLE IF NOT EXISTS "api_tokens"
(
apiTokenId TEXT PRIMARY KEY NOT NULL,
diff --git a/src/services/note_cache.js b/src/services/note_cache.js
index dfdc2ae35..74b339c01 100644
--- a/src/services/note_cache.js
+++ b/src/services/note_cache.js
@@ -26,7 +26,10 @@ async function load() {
noteTitles = await sql.getMap(`SELECT noteId, title FROM notes WHERE isDeleted = 0 AND isProtected = 0`);
noteIds = Object.keys(noteTitles);
- prefixes = await sql.getMap(`SELECT noteId || '-' || parentNoteId, prefix FROM branches WHERE prefix IS NOT NULL AND prefix != ''`);
+ prefixes = await sql.getMap(`
+ SELECT noteId || '-' || parentNoteId, prefix
+ FROM branches
+ WHERE isDeleted = 0 AND prefix IS NOT NULL AND prefix != ''`);
const branches = await sql.getRows(`SELECT branchId, noteId, parentNoteId FROM branches WHERE isDeleted = 0`);