Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Discover
Commits
ab6ce441
Commit
ab6ce441
authored
Feb 05, 2021
by
Aleix Pol Gonzalez
🐧
Committed by
Aleix Pol Gonzalez
Feb 09, 2021
Browse files
odrs: Move JSON parsing to a separate thread
This way we make sure it doesn't block the main thread
parent
dd18487e
Changes
1
Hide whitespace changes
Inline
Side-by-side
libdiscover/appstream/OdrsReviewsBackend.cpp
View file @
ab6ce441
...
...
@@ -30,6 +30,9 @@
#include <QNetworkRequest>
#include <QStandardPaths>
#include <QtConcurrentRun>
#include <QFutureWatcher>
// #define APIURL "http://127.0.0.1:5000/1.0/reviews/api"
#define APIURL "https://odrs.gnome.org/1.0/reviews/api"
...
...
@@ -243,9 +246,10 @@ void OdrsReviewsBackend::reviewSubmitted(QNetworkReply *reply)
void
OdrsReviewsBackend
::
parseRatings
()
{
QFile
ratingsDocument
(
QStandardPaths
::
writableLocation
(
QStandardPaths
::
CacheLocation
)
+
QStringLiteral
(
"/ratings/ratings"
));
if
(
ratingsDocument
.
open
(
QIODevice
::
ReadOnly
))
{
QJsonDocument
jsonDocument
=
QJsonDocument
::
fromJson
(
ratingsDocument
.
readAll
());
auto
fw
=
new
QFutureWatcher
<
QJsonDocument
>
(
this
);
connect
(
fw
,
&
QFutureWatcher
<
QJsonDocument
>::
finished
,
this
,
[
this
,
fw
]
{
const
QJsonDocument
jsonDocument
=
fw
->
result
();
fw
->
deleteLater
();
const
QJsonObject
jsonObject
=
jsonDocument
.
object
();
m_ratings
.
reserve
(
jsonObject
.
size
());
for
(
auto
it
=
jsonObject
.
begin
();
it
!=
jsonObject
.
end
();
it
++
)
{
...
...
@@ -262,10 +266,15 @@ void OdrsReviewsBackend::parseRatings()
Rating
*
rating
=
new
Rating
(
it
.
key
(),
ratingCount
,
ratingMap
);
m_ratings
.
insert
(
it
.
key
(),
rating
);
}
ratingsDocument
.
close
();
Q_EMIT
ratingsReady
();
}
});
fw
->
setFuture
(
QtConcurrent
::
run
([]
{
QFile
ratingsDocument
(
QStandardPaths
::
writableLocation
(
QStandardPaths
::
CacheLocation
)
+
QStringLiteral
(
"/ratings/ratings"
));
if
(
!
ratingsDocument
.
open
(
QIODevice
::
ReadOnly
))
{
return
QJsonDocument
::
fromJson
({});
}
return
QJsonDocument
::
fromJson
(
ratingsDocument
.
readAll
());
}));
}
void
OdrsReviewsBackend
::
parseReviews
(
const
QJsonDocument
&
document
,
AbstractResource
*
resource
)
...
...
Aleix Pol Gonzalez
🐧
@apol
mentioned in commit
f13b07d3
·
Feb 09, 2021
mentioned in commit
f13b07d3
mentioned in commit f13b07d358818a45d6872c6a1ea7bb7b30931cbb
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment