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

2
src/persistence/history.h

@ -82,7 +82,7 @@ public: @@ -82,7 +82,7 @@ public:
const QDateTime& 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);

19
src/widget/form/chatform.cpp

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

Loading…
Cancel
Save