Skip to content

Commit c121732

Browse files
committed
Fix issue #3518: Fix score in zsets
1 parent f214922 commit c121732

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

src/app/models/key-models/sortedsetkey.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ QVariant SortedSetKeyModel::getData(int rowIndex, int dataRole)
3232
if (!isRowLoaded(rowIndex))
3333
return QVariant();
3434

35-
QPair<QByteArray, double> row = m_rowsCache[rowIndex];
35+
QPair<QByteArray, QByteArray> row = m_rowsCache[rowIndex];
3636

3737
if (dataRole == Roles::Value)
3838
return row.first;
3939
else if (dataRole ==Roles::Score)
40-
return QString::number(row.second);
40+
return row.second;
4141
else if (dataRole == Roles::RowNumber)
4242
return QString::number(rowIndex+1);
4343

@@ -49,14 +49,14 @@ void SortedSetKeyModel::updateRow(int rowIndex, const QVariantMap &row)
4949
if (!isRowLoaded(rowIndex) || !isRowValid(row))
5050
throw Exception("Invalid row");
5151

52-
QPair<QByteArray, double> cachedRow = m_rowsCache[rowIndex];
52+
QPair<QByteArray, QByteArray> cachedRow = m_rowsCache[rowIndex];
5353

5454
bool valueChanged = cachedRow.first != row["value"].toString();
55-
bool scoreChanged = cachedRow.second != row["score"].toDouble();
55+
bool scoreChanged = cachedRow.second != row["score"].toString();
5656

57-
QPair<QByteArray, double> newRow(
57+
QPair<QByteArray, QByteArray> newRow(
5858
(valueChanged) ? row["value"].toByteArray() : cachedRow.first,
59-
(scoreChanged) ? row["score"].toDouble() : cachedRow.second
59+
(scoreChanged) ? row["score"].toByteArray() : cachedRow.second
6060
);
6161

6262
// TODO (uglide): Update only score if value not changed
@@ -71,9 +71,9 @@ void SortedSetKeyModel::addRow(const QVariantMap &row)
7171
if (!isRowValid(row))
7272
throw Exception("Invalid row");
7373

74-
QPair<QByteArray, double> cachedRow(
74+
QPair<QByteArray, QByteArray> cachedRow(
7575
row["value"].toByteArray(),
76-
row["score"].toDouble());
76+
row["score"].toByteArray());
7777

7878
if (addSortedSetRow(cachedRow.first, cachedRow.second)) {
7979
m_rowsCache.push_back(cachedRow);
@@ -99,12 +99,12 @@ void SortedSetKeyModel::removeRow(int i)
9999
setRemovedIfEmpty();
100100
}
101101

102-
bool SortedSetKeyModel::addSortedSetRow(const QByteArray &value, double score)
102+
bool SortedSetKeyModel::addSortedSetRow(const QByteArray &value, QByteArray score)
103103
{
104104
RedisClient::Response result;
105105
try {
106106
result = m_connection->commandSync(
107-
{"ZADD", m_keyFullPath, QString::number(score).toLatin1(), value}, m_dbIndex);
107+
{"ZADD", m_keyFullPath, score, value}, m_dbIndex);
108108
} catch (const RedisClient::Connection::Exception& e) {
109109
throw Exception("Connection error: " + QString(e.what()));
110110
}
@@ -123,19 +123,19 @@ void SortedSetKeyModel::deleteSortedSetRow(const QByteArray &value)
123123

124124
void SortedSetKeyModel::addLoadedRowsToCache(const QVariantList &rows, int rowStart)
125125
{
126-
QList<QPair<QByteArray, double>> result;
126+
QList<QPair<QByteArray, QByteArray>> result;
127127

128128
for (QVariantList::const_iterator item = rows.begin();
129129
item != rows.end(); ++item) {
130130

131-
QPair<QByteArray, double> value;
131+
QPair<QByteArray, QByteArray> value;
132132
value.first = item->toByteArray();
133133
++item;
134134

135135
if (item == rows.end())
136136
throw Exception("Partial data loaded from server");
137137

138-
value.second = item->toDouble();
138+
value.second = item->toByteArray();
139139
result.push_back(value);
140140
}
141141

src/app/models/key-models/sortedsetkey.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
#include "abstractkey.h"
33

4-
class SortedSetKeyModel : public KeyModel<QPair<QByteArray, double>>
4+
class SortedSetKeyModel : public KeyModel<QPair<QByteArray, QByteArray>>
55
{
66
public:
77
SortedSetKeyModel(QSharedPointer<RedisClient::Connection> connection,
@@ -22,6 +22,6 @@ class SortedSetKeyModel : public KeyModel<QPair<QByteArray, double>>
2222
private:
2323
enum Roles { Value = Qt::UserRole + 1, Score, RowNumber};
2424

25-
bool addSortedSetRow(const QByteArray &value, double score);
25+
bool addSortedSetRow(const QByteArray &value, QByteArray score);
2626
void deleteSortedSetRow(const QByteArray& value);
2727
};

src/resources/qml/ValueTabs.qml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ Repeater {
228228
return ""
229229

230230
if (styleData.column === 2 && keyType == "zset") {
231-
var locale = Qt.locale("C")
232-
return Number(styleData.value).toLocaleString(locale, "f")
231+
return parseFloat(Number(styleData.value).toFixed(20))
233232
}
234233

235234
return binaryUtils.printable(styleData.value)

src/resources/qml/editors/SortedSetItemEditor.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ AbstractEditor {
4040

4141
function setValue(rowValue) {
4242
scoreText.originalValue = rowValue['score']
43-
scoreText.text = Number(rowValue['score']).toFixed(20)
43+
scoreText.text = parseFloat(Number(rowValue['score']).toFixed(20))
4444
textArea.originalValue = rowValue['value']
4545
textArea.setValue(rowValue['value'])
4646
}

0 commit comments

Comments
 (0)