mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-08-07 19:13:28 +00:00
Fix issue #2077 part 2. Only sort when actually necessary.
Signed-off-by: Adam Treat <treat.adam@gmail.com>
This commit is contained in:
parent
fc169e739a
commit
4251b7beaa
@ -802,12 +802,22 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We only sort when one of the fields used by the sorting algorithm actually changes that
|
||||||
|
// is implicated or used by the sorting algorithm
|
||||||
|
bool shouldSort = false;
|
||||||
|
|
||||||
for (const auto &d : data) {
|
for (const auto &d : data) {
|
||||||
const int role = d.first;
|
const int role = d.first;
|
||||||
const QVariant value = d.second;
|
const QVariant value = d.second;
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case IdRole:
|
case IdRole:
|
||||||
info->setId(value.toString()); break;
|
{
|
||||||
|
if (info->id() != value.toString()) {
|
||||||
|
info->setId(value.toString());
|
||||||
|
shouldSort = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case NameRole:
|
case NameRole:
|
||||||
info->setName(value.toString()); break;
|
info->setName(value.toString()); break;
|
||||||
case FilenameRole:
|
case FilenameRole:
|
||||||
@ -853,7 +863,13 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
|
|||||||
case DownloadErrorRole:
|
case DownloadErrorRole:
|
||||||
info->downloadError = value.toString(); break;
|
info->downloadError = value.toString(); break;
|
||||||
case OrderRole:
|
case OrderRole:
|
||||||
info->order = value.toString(); break;
|
{
|
||||||
|
if (info->order != value.toString()) {
|
||||||
|
info->order = value.toString();
|
||||||
|
shouldSort = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case RamrequiredRole:
|
case RamrequiredRole:
|
||||||
info->ramrequired = value.toInt(); break;
|
info->ramrequired = value.toInt(); break;
|
||||||
case ParametersRole:
|
case ParametersRole:
|
||||||
@ -863,9 +879,21 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
|
|||||||
case TypeRole:
|
case TypeRole:
|
||||||
info->setType(value.toString()); break;
|
info->setType(value.toString()); break;
|
||||||
case IsCloneRole:
|
case IsCloneRole:
|
||||||
info->setIsClone(value.toBool()); break;
|
{
|
||||||
|
if (info->isClone() != value.toBool()) {
|
||||||
|
info->setIsClone(value.toBool());
|
||||||
|
shouldSort = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case IsDiscoveredRole:
|
case IsDiscoveredRole:
|
||||||
info->setIsDiscovered(value.toBool()); break;
|
{
|
||||||
|
if (info->isDiscovered() != value.toBool()) {
|
||||||
|
info->setIsDiscovered(value.toBool());
|
||||||
|
shouldSort = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case TemperatureRole:
|
case TemperatureRole:
|
||||||
info->setTemperature(value.toDouble()); break;
|
info->setTemperature(value.toDouble()); break;
|
||||||
case TopPRole:
|
case TopPRole:
|
||||||
@ -891,11 +919,29 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
|
|||||||
case SystemPromptRole:
|
case SystemPromptRole:
|
||||||
info->setSystemPrompt(value.toString()); break;
|
info->setSystemPrompt(value.toString()); break;
|
||||||
case LikesRole:
|
case LikesRole:
|
||||||
info->setLikes(value.toInt()); break;
|
{
|
||||||
|
if (info->likes() != value.toInt()) {
|
||||||
|
info->setLikes(value.toInt());
|
||||||
|
shouldSort = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DownloadsRole:
|
case DownloadsRole:
|
||||||
info->setDownloads(value.toInt()); break;
|
{
|
||||||
|
if (info->downloads() != value.toInt()) {
|
||||||
|
info->setDownloads(value.toInt());
|
||||||
|
shouldSort = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case RecencyRole:
|
case RecencyRole:
|
||||||
info->setRecency(value.toDateTime()); break;
|
{
|
||||||
|
if (info->recency() != value.toDateTime()) {
|
||||||
|
info->setRecency(value.toDateTime());
|
||||||
|
shouldSort = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -905,11 +951,13 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
|
|||||||
const QFileInfo incompleteInfo(incompleteDownloadPath(info->filename()));
|
const QFileInfo incompleteInfo(incompleteDownloadPath(info->filename()));
|
||||||
info->isIncomplete = incompleteInfo.exists();
|
info->isIncomplete = incompleteInfo.exists();
|
||||||
|
|
||||||
auto s = m_discoverSort;
|
if (shouldSort) {
|
||||||
auto d = m_discoverSortDirection;
|
auto s = m_discoverSort;
|
||||||
std::stable_sort(m_models.begin(), m_models.end(), [s, d](const ModelInfo* lhs, const ModelInfo* rhs) {
|
auto d = m_discoverSortDirection;
|
||||||
return ModelList::lessThan(lhs, rhs, s, d);
|
std::stable_sort(m_models.begin(), m_models.end(), [s, d](const ModelInfo* lhs, const ModelInfo* rhs) {
|
||||||
});
|
return ModelList::lessThan(lhs, rhs, s, d);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emit dataChanged(createIndex(index, 0), createIndex(index, 0));
|
emit dataChanged(createIndex(index, 0), createIndex(index, 0));
|
||||||
emit userDefaultModelListChanged();
|
emit userDefaultModelListChanged();
|
||||||
|
Loading…
Reference in New Issue
Block a user