1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

feat: optimise search in history

This commit is contained in:
TriKriSta 2018-02-12 01:02:28 +02:00
parent 7718734c9a
commit 18fa8a745b
3 changed files with 13 additions and 19 deletions

View File

@ -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)
"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});

View File

@ -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);

View File

@ -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)
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);