MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / flushCache

Method flushCache

threads/indexrunner.cpp:469–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

467
468
469void IndexRunner::flushCache() {
470 if (indexHash->size() <= 0)
471 return;
472 QDateTime start = QDateTime::currentDateTimeUtc();
473 NSqlQuery sql(db);
474 db->lockForWrite();
475 sql.exec("begin");
476 QHash<qint32, IndexRecord*>::iterator i;
477
478 // Start adding words to the index. Every 200 sql insertions we do a commit
479 int commitCount = 200;
480
481 for (i=indexHash->begin(); keepRunning && !pauseIndexing && i!=indexHash->end(); ++i) {
482 qint32 lid = i.key();
483 IndexRecord *rec = i.value();
484 qint32 weight = rec->weight;
485 QString source = rec->source;
486 QString content = rec->content;
487 delete rec;
488
489 // Delete any old content
490 sql.prepare("Delete from SearchIndex where lid=:lid and source=:source");
491 sql.bindValue(":lid", lid);
492 sql.bindValue(":source", source);
493 sql.exec();
494
495 // Add the new content. it is basically a text version of the note with a weight of 100.
496 sql.prepare("Insert into SearchIndex (lid, weight, source, content) values (:lid, :weight, :source, :content)");
497 sql.bindValue(":lid", lid);
498 sql.bindValue(":weight", weight);
499 sql.bindValue(":source", source);
500 if (!global.forceSearchLowerCase)
501 sql.bindValue(":content", content);
502 else
503 sql.bindValue(":content", content.toLower());
504 sql.exec();
505 commitCount--;
506 if (commitCount <= 0) {
507 sql.exec("commit");
508 commitCount = 200;
509 }
510 }
511 indexHash->clear();
512 sql.exec("commit");
513
514 sql.finish();
515 db->unlock();
516 QDateTime finish = QDateTime::currentDateTimeUtc();
517
518 QLOG_DEBUG() << "Index Cache Flush Complete: " <<
519 finish.toMSecsSinceEpoch() - start.toMSecsSinceEpoch()
520 << " milliseconds.";
521}
522
523
524

Callers

nothing calls this directly

Calls 7

lockForWriteMethod · 0.80
valueMethod · 0.80
bindValueMethod · 0.80
execMethod · 0.45
prepareMethod · 0.45
clearMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected