Skip to content

Commit

Permalink
Do not rewrite all the notes on the disk when one is deleted
Browse files Browse the repository at this point in the history
that's still issue #43
  • Loading branch information
maoschanz committed Jun 6, 2020
1 parent 2a7d95c commit 8f63ba8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ Notes are stored in files at `~/.local/share/notes@maestroschan.fr/*_text`

<!-- TODO
pas de raise correct quand on focus une note sans focus automatique
faut réécrire comment ça interagit avec le disque
mettre le putain d'array en attribut du singleton "notesmanager"
pas de raise correct quand on focus une note sans focus automatique
"éditer le titre" dans le menu
le bouton de grab aurait le titre en label, et clic-droit enroulerait
sa mère faut réécrire comment ça interagit avec le disque, là c'est hoooonteux
-->

Expand Down
34 changes: 9 additions & 25 deletions notes@maestroschan.fr/extension.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,17 @@ class NotesManager {
}

/*
* When a NoteBox object deletes itself, it calls this horrible thing to
* ensure the files go from 1 to (ALL_NOTES.length - 1) without any "gap" in
* the numerotation.
* When a NoteBox object deletes itself, it calls this method to ensure the
* files go from 0 to (ALL_NOTES.length - 1) without any "gap" in the
* numerotation.
*/
postDelete () {
// Rebuild a fresh ALL_NOTES array from the existing NoteBox objects
let temp = new Array();
ALL_NOTES.forEach(function (n) {
if (n.actor == null) {
// nothing
} else {
n.id = temp.length;
temp.push(n);
}
});
ALL_NOTES = null;
ALL_NOTES = temp;

// Delete the file with the biggest id (the other will be overwritten)
postDelete (deletedNoteId) {
let lastNote = ALL_NOTES.pop();
if (deletedNoteId < ALL_NOTES.length) {
ALL_NOTES[deletedNoteId] = lastNote;
lastNote.id = deletedNoteId;
}
this._deleteNoteFiles(ALL_NOTES.length);

// Save all notes from the ALL_NOTES array to the disk
ALL_NOTES.forEach(function (n) {
if(n.actor != null) {
n.onlySave();
}
});
}

/*
Expand Down
3 changes: 2 additions & 1 deletion notes@maestroschan.fr/noteBox.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,9 @@ var NoteBox = class NoteBox {
//--------------------------------------------------------------------------

_deleteNoteObject () {
let noteId = this.id;
this.destroy();
Extension.NOTES_MANAGER.postDelete();
Extension.NOTES_MANAGER.postDelete(noteId);
}

destroy () {
Expand Down

0 comments on commit 8f63ba8

Please sign in to comment.