Skip to content

Commit f706d4e

Browse files
committedApr 23, 2023
Add network request initiators to remote COPC/EPT code
This will make it easier to identify where the individual requests are coming from (which is harder especially with COPC where byte ranges are fetched from the same file) Also switch hierarchy fetching in EPT to use QgsTileDownloadManager like used for COPC. This will ensure that in case of multiple requests in parallel there will be just one going out.
1 parent eea6b1c commit f706d4e

File tree

5 files changed

+22
-25
lines changed

5 files changed

+22
-25
lines changed
 

‎src/core/pointcloud/qgscopcpointcloudblockrequest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "qgstiledownloadmanager.h"
2121
#include "qgslazdecoder.h"
2222
#include "qgsapplication.h"
23-
#include "qgsremotecopcpointcloudindex.h"
23+
#include "qgsnetworkaccessmanager.h"
2424

2525
//
2626
// QgsCopcPointCloudBlockRequest
@@ -36,6 +36,8 @@ QgsCopcPointCloudBlockRequest::QgsCopcPointCloudBlockRequest( const IndexedPoint
3636
mBlockOffset( blockOffset ), mBlockSize( blockSize ), mPointCount( pointCount ), mLazInfo( lazInfo )
3737
{
3838
QNetworkRequest nr( mUri );
39+
QgsSetRequestInitiatorClass( nr, QStringLiteral( "QgsCopcPointCloudBlockRequest" ) );
40+
QgsSetRequestInitiatorId( nr, node.toString() );
3941
nr.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
4042
nr.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
4143

‎src/core/pointcloud/qgseptpointcloudblockrequest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "qgseptdecoder.h"
2222
#include "qgslazdecoder.h"
2323
#include "qgsapplication.h"
24-
#include "qgsremoteeptpointcloudindex.h"
24+
#include "qgsnetworkaccessmanager.h"
2525

2626
//
2727
// QgsEptPointCloudBlockRequest
@@ -36,6 +36,8 @@ QgsEptPointCloudBlockRequest::QgsEptPointCloudBlockRequest( const IndexedPointCl
3636
mDataType( dataType )
3737
{
3838
QNetworkRequest nr( mUri );
39+
QgsSetRequestInitiatorClass( nr, QStringLiteral( "QgsEptPointCloudBlockRequest" ) );
40+
QgsSetRequestInitiatorId( nr, node.toString() );
3941
nr.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
4042
nr.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
4143
mTileDownloadManagerReply.reset( QgsApplication::tileDownloadManager()->get( nr ) );

‎src/core/pointcloud/qgslazinfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "qgslogger.h"
2121
#include "qgsblockingnetworkrequest.h"
22+
#include "qgsnetworkaccessmanager.h"
2223

2324
#include "lazperf/readers.hpp"
2425

@@ -302,6 +303,7 @@ QgsLazInfo QgsLazInfo::fromUrl( QUrl &url )
302303
// Fetch header data
303304
{
304305
QNetworkRequest nr( url );
306+
QgsSetRequestInitiatorClass( nr, QStringLiteral( "QgsLazInfo" ) );
305307
nr.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork );
306308
nr.setAttribute( QNetworkRequest::CacheSaveControlAttribute, false );
307309
nr.setRawHeader( "Range", "bytes=0-374" );

‎src/core/pointcloud/qgsremotecopcpointcloudindex.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,14 @@
2828
#include <QQueue>
2929
#include <QTimer>
3030

31-
#include "qgseptdecoder.h"
32-
#include "qgscoordinatereferencesystem.h"
3331
#include "qgspointcloudrequest.h"
3432
#include "qgspointcloudattribute.h"
3533
#include "qgslogger.h"
36-
#include "qgsfeedback.h"
37-
#include "qgsmessagelog.h"
38-
3934
#include "qgstiledownloadmanager.h"
40-
#include "qgsblockingnetworkrequest.h"
41-
#include "qgslazdecoder.h"
42-
#include "qgsfileutils.h"
4335
#include "qgsapplication.h"
4436
#include "qgscopcpointcloudblockrequest.h"
4537
#include "qgspointcloudexpression.h"
38+
#include "qgsnetworkaccessmanager.h"
4639

4740
///@cond PRIVATE
4841

@@ -180,6 +173,7 @@ bool QgsRemoteCopcPointCloudIndex::isValid() const
180173
void QgsRemoteCopcPointCloudIndex::fetchHierarchyPage( uint64_t offset, uint64_t byteSize ) const
181174
{
182175
QNetworkRequest nr( mUrl );
176+
QgsSetRequestInitiatorClass( nr, QStringLiteral( "QgsRemoteCopcPointCloudIndex" ) );
183177
nr.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
184178
nr.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
185179
QByteArray queryRange = QStringLiteral( "bytes=%1-%2" ).arg( offset ).arg( offset + byteSize - 1 ).toLocal8Bit();

‎src/core/pointcloud/qgsremoteeptpointcloudindex.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,16 @@
2828
#include <QQueue>
2929
#include <QTimer>
3030

31-
#include "qgseptdecoder.h"
32-
#include "qgscoordinatereferencesystem.h"
31+
#include "qgsapplication.h"
3332
#include "qgspointcloudrequest.h"
3433
#include "qgspointcloudattribute.h"
3534
#include "qgslogger.h"
3635
#include "qgsfeedback.h"
37-
#include "qgsmessagelog.h"
38-
3936
#include "qgstiledownloadmanager.h"
4037
#include "qgsblockingnetworkrequest.h"
41-
42-
#include "qgsfileutils.h"
43-
#include "qgsapplication.h"
4438
#include "qgseptpointcloudblockrequest.h"
4539
#include "qgspointcloudexpression.h"
40+
#include "qgsnetworkaccessmanager.h"
4641

4742
///@cond PRIVATE
4843

@@ -198,21 +193,23 @@ bool QgsRemoteEptPointCloudIndex::loadNodeHierarchy( const IndexedPointCloudNode
198193

199194
const QString fileUrl = QStringLiteral( "%1/ept-hierarchy/%2.json" ).arg( mUrlDirectoryPart, node.toString() );
200195
QNetworkRequest nr( fileUrl );
201-
196+
QgsSetRequestInitiatorClass( nr, QStringLiteral( "QgsRemoteEptPointCloudIndex" ) );
202197
nr.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
203198
nr.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
204199

205-
QgsBlockingNetworkRequest req;
206-
const QgsBlockingNetworkRequest::ErrorCode errCode = req.get( nr );
207-
if ( errCode != QgsBlockingNetworkRequest::NoError )
200+
std::unique_ptr<QgsTileDownloadManagerReply> reply( QgsApplication::tileDownloadManager()->get( nr ) );
201+
202+
QEventLoop loop;
203+
connect( reply.get(), &QgsTileDownloadManagerReply::finished, &loop, &QEventLoop::quit );
204+
loop.exec();
205+
206+
if ( reply->error() != QNetworkReply::NoError )
208207
{
209-
QgsDebugMsgLevel( QStringLiteral( "unable to read hierarchy from file %1" ).arg( fileUrl ), 2 );
208+
QgsDebugMsg( QStringLiteral( "Request failed: " ) + mUrl.toString() );
210209
return false;
211210
}
212211

213-
const QgsNetworkReplyContent reply = req.reply();
214-
215-
const QByteArray dataJsonH = reply.content();
212+
const QByteArray dataJsonH = reply->data();
216213
QJsonParseError errH;
217214
const QJsonDocument docH = QJsonDocument::fromJson( dataJsonH, &errH );
218215
if ( errH.error != QJsonParseError::NoError )

0 commit comments

Comments
 (0)
Please sign in to comment.