Browse Source

feat: optimise search in history

reviewable/pr4955/r3
TriKriSta 8 years ago
parent
commit
18fa8a745b
  1. 11
      src/persistence/history.cpp
  2. 2
      src/persistence/history.h
  3. 19
      src/widget/form/chatform.cpp

11
src/persistence/history.cpp

@ -326,7 +326,7 @@ QList<History::DateMessages> History::getChatHistoryCounts(const ToxPk& friendPk
return counts; return counts;
} }
QDateTime History::getStartDateChatHistory(const QString& friendPk) QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, const QString& phrase)
{ {
QList<QDateTime> counts; QList<QDateTime> counts;
auto rowCallback = [&counts](const QVector<QVariant>& row) { auto rowCallback = [&counts](const QVector<QVariant>& row) {
@ -338,8 +338,13 @@ QDateTime History::getStartDateChatHistory(const QString& friendPk)
"FROM history " "FROM history "
"LEFT JOIN faux_offline_pending ON history.id = faux_offline_pending.id " "LEFT JOIN faux_offline_pending ON history.id = faux_offline_pending.id "
"JOIN peers chat ON chat_id = chat.id " "JOIN peers chat ON chat_id = chat.id "
"WHERE chat.public_key='%1' ORDER BY timestamp ASC LIMIT 1;") "WHERE chat.public_key='%1' "
.arg(friendPk); "AND message LIKE '%%2%' "
"AND timestamp < '%3' ORDER BY timestamp DESC LIMIT 1;")
.arg(friendPk)
.arg(phrase)
.arg(from.toMSecsSinceEpoch());
db->execNow({queryText, rowCallback}); db->execNow({queryText, rowCallback});

2
src/persistence/history.h

@ -82,7 +82,7 @@ public:
const QDateTime& to); const QDateTime& to);
QList<DateMessages> getChatHistoryCounts(const ToxPk& friendPk, const QDate& from, const QDate& to); QList<DateMessages> getChatHistoryCounts(const ToxPk& friendPk, const QDate& from, const QDate& to);
QDateTime getStartDateChatHistory(const QString& friendPk); QDateTime getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, const QString& phrase);
void markAsSent(qint64 messageId); void markAsSent(qint64 messageId);

19
src/widget/form/chatform.cpp

@ -502,18 +502,12 @@ void ChatForm::onSearchUp(const QString& phrase)
if (startLine == 0) { if (startLine == 0) {
QString pk = f->getPublicKey().toString(); QString pk = f->getPublicKey().toString();
QDateTime startDate = history->getStartDateChatHistory(pk); QDateTime newBaseData = history->getDateWhereFindPhrase(pk, earliestMessage, phrase);
if (!startDate.isValid() || startDate == earliestMessage) { if (!newBaseData.isValid()) {
return; return;
} }
QDateTime newBaseData = earliestMessage.addDays(-1);
if (startDate > newBaseData) {
newBaseData = startDate;
}
searchAfterLoadHistory = true; searchAfterLoadHistory = true;
loadHistory(newBaseData); loadHistory(newBaseData);
@ -524,17 +518,12 @@ void ChatForm::onSearchUp(const QString& phrase)
if (!isSearch) { if (!isSearch) {
QString pk = f->getPublicKey().toString(); QString pk = f->getPublicKey().toString();
QDateTime startDate = history->getStartDateChatHistory(pk); QDateTime newBaseData = history->getDateWhereFindPhrase(pk, earliestMessage, phrase);
QDateTime newBaseData = earliestMessage.addDays(-1);
if (!startDate.isValid()) { if (!newBaseData.isValid()) {
return; return;
} }
if (startDate > newBaseData) {
newBaseData = startDate;
}
searchPoint.setX(numLines); searchPoint.setX(numLines);
searchAfterLoadHistory = true; searchAfterLoadHistory = true;
loadHistory(newBaseData); loadHistory(newBaseData);

Loading…
Cancel
Save