@@ -56,7 +56,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5656 In older versions the notes were stored as a bundle of separate files.
5757 In newer versions each note is stored as one JSON file.
5858 This uses less space on disk.
59- In older versions, on a Linux server, one notes took 32 kbytes.
59+ In older versions, on a Linux server, one note took 32 kbytes.
6060 A lot of that space is wasted.
6161 In newer versions one notes takes only 4 kbytes.
6262 That is a difference of 8 times.
@@ -184,21 +184,21 @@ bool Database_Notes::checkup_checksums ()
184184void Database_Notes::trim ()
185185{
186186 // Clean empty directories.
187- std::string message = " Deleting empty notes folder " ;
188- std::string main_folder = main_folder_path ();
189- std::vector <std::string> bits1 = filter_url_scandir (main_folder);
190- for (auto bit1 : bits1) {
187+ const std::string message = " Deleting empty notes folder " ;
188+ const std::string main_folder = main_folder_path ();
189+ const std::vector <std::string> bits1 = filter_url_scandir (main_folder);
190+ for (const auto & bit1 : bits1) {
191191 if (bit1.length () == 3 ) {
192- std::string folder1 = filter_url_create_path ({main_folder, bit1});
193- std::vector <std::string> bits2 = filter_url_scandir (folder1);
192+ const std::string folder1 = filter_url_create_path ({main_folder, bit1});
193+ const std::vector <std::string> bits2 = filter_url_scandir (folder1);
194194 if (bits2.empty ()) {
195195 Database_Logs::log (message + folder1);
196196 remove (folder1.c_str ());
197197 }
198- for (auto bit2 : bits2) {
198+ for (const auto & bit2 : bits2) {
199199 if (bit2.length () == 3 ) {
200- std::string folder2 = filter_url_create_path ({main_folder, bit1, bit2});
201- std::vector <std::string> bits3 = filter_url_scandir (folder2);
200+ const std::string folder2 = filter_url_create_path ({main_folder, bit1, bit2});
201+ const std::vector <std::string> bits3 = filter_url_scandir (folder2);
202202 if (bits3.empty ()) {
203203 Database_Logs::log (message + folder2);
204204 remove (folder2.c_str ());
@@ -214,11 +214,9 @@ void Database_Notes::trim_server ()
214214{
215215 // Notes expiry.
216216 touch_marked_for_deletion ();
217- // / Storage for notes to be deleted.
218- std::vector <int > identifiers;
219- // Deal with new notes storage in JSON.
220- identifiers = get_due_for_deletion ();
221- for (auto & identifier : identifiers) {
217+ // Storage for notes to be deleted.
218+ const std::vector <int > identifiers = get_due_for_deletion ();
219+ for (const auto identifier : identifiers) {
222220 trash_consultation_note (m_webserver_request, identifier);
223221 erase (identifier);
224222 }
@@ -233,35 +231,35 @@ void Database_Notes::optimize ()
233231}
234232
235233
236- void Database_Notes::sync ()
234+ void Database_Notes::sync () // Todo
237235{
238- std::string main_folder = main_folder_path ();
236+ const std::string main_folder = main_folder_path ();
239237
240238 // List of notes in the filesystem.
241239 std::vector <int > identifiers;
242240
243- std::vector <std::string> bits1 = filter_url_scandir (main_folder);
244- for (auto & bit1 : bits1) {
241+ const std::vector <std::string> bits1 = filter_url_scandir (main_folder);
242+ for (const auto & bit1 : bits1) {
245243 // Bit 1 / 2 / 3 may start with a 0, so conversion to int cannot be used, rather use a length of 3.
246244 // It used conversion to int before to determine it was a real note,
247245 // with the result that it missed 10% of the notes, which subsequently got deleted, oops!
248246 if (bit1.length () == 3 ) {
249- std::vector <std::string> bits2 = filter_url_scandir (filter_url_create_path ({main_folder, bit1}));
250- for (auto & bit2 : bits2) {
247+ const std::vector <std::string> bits2 = filter_url_scandir (filter_url_create_path ({main_folder, bit1}));
248+ for (const auto & bit2 : bits2) {
251249 // Old storage mechanism, e.g. folder "425".
252250 if (bit2.length () == 3 ) {
253- std::vector <std::string> bits3 = filter_url_scandir (filter_url_create_path ({main_folder, bit1, bit2}));
254- for (auto & bit3 : bits3) {
251+ const std::vector <std::string> bits3 = filter_url_scandir (filter_url_create_path ({main_folder, bit1, bit2}));
252+ for (const auto & bit3 : bits3) {
255253 if (bit3.length () == 3 ) {
256- int identifier = filter::strings::convert_to_int (bit1 + bit2 + bit3);
254+ const int identifier = filter::strings::convert_to_int (bit1 + bit2 + bit3);
257255 identifiers.push_back (identifier);
258256 update_search_fields (identifier);
259257 }
260258 }
261259 }
262- // New JSON storage mechanism, e.g. file "894093.json".
260+ // New JSON storage mechanism, e.g. file "894093.json". Todo
263261 if ((bit2.length () == 11 ) && bit2.find (" .json" ) != std::string::npos) {
264- int identifier = filter::strings::convert_to_int (bit1 + bit2.substr (0 ,6 ));
262+ const int identifier = filter::strings::convert_to_int (bit1 + bit2.substr (0 ,6 ));
265263 identifiers.push_back (identifier);
266264 update_database (identifier);
267265 update_search_fields (identifier);
@@ -404,9 +402,9 @@ std::string Database_Notes::note_file (int identifier)
404402{
405403 // The maximum number of folders a folder may contain is constrained by the filesystem.
406404 // To overcome this, the notes will be stored in a folder structure.
407- std::string sidentifier = std::to_string (identifier);
408- std::string folder = sidentifier .substr (0 , 3 );
409- std::string file = sidentifier .substr (3 , 6 ) + " .json" ;
405+ const std::string id_path = std::to_string (identifier);
406+ const std::string folder = id_path .substr (0 , 3 );
407+ const std::string file = id_path .substr (3 , 6 ) + " .json" ;
410408 return filter_url_create_path ({main_folder_path (), folder, file});
411409}
412410
@@ -1882,15 +1880,15 @@ std::vector <std::string> Database_Notes::set_bulk (std::string json)
18821880
18831881
18841882// Gets a field from a note in JSON format.
1885- std::string Database_Notes::get_field (int identifier, std::string key)
1883+ std::string Database_Notes::get_field (int identifier, const std::string& key) // Todo
18861884{
1887- std::string file = note_file (identifier);
1888- std::string json = filter_url_file_get_contents (file);
1885+ const std::string file = note_file (identifier);
1886+ const std::string json = filter_url_file_get_contents (file);
18891887 jsonxx::Object note;
18901888 note.parse (json);
1891- std::string value;
1892- if (note. has <jsonxx::String> (key)) value = note.get <jsonxx::String> (key);
1893- return value ;
1889+ if (note. has <jsonxx::String> (key))
1890+ return note.get <jsonxx::String> (key);
1891+ return std::string () ;
18941892}
18951893
18961894
0 commit comments