Skip to content

Commit 4e589da

Browse files
committed
reworking queries to include pagination
1 parent 70f9fc8 commit 4e589da

4 files changed

Lines changed: 73 additions & 18 deletions

File tree

pydex/classes/RiverscapesAPI.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Dict, List, Generator, Tuple
44
import webbrowser
55
import re
6+
import math
67
import time
78
import concurrent.futures
89
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
@@ -490,8 +491,29 @@ def get_project_full(self, project_id: str) -> RiverscapesProject:
490491
_type_: _description_
491492
"""
492493
qry = self.load_query('getProjectFull')
493-
results = self.run_query(qry, {"id": project_id})
494-
return RiverscapesProject(results['data']['project'])
494+
495+
limit = 500
496+
offset = 0
497+
498+
results = self.run_query(qry, {"id": project_id, "fileLimit": limit, "fileOffset": offset})
499+
project_data = results['data']['project']
500+
501+
files_meta = project_data.get('files')
502+
if files_meta and 'total' in files_meta:
503+
total = files_meta.get('total', 0)
504+
items = files_meta.get('items', [])
505+
506+
if total > limit:
507+
# Calculate how many extra pages we need to fetch
508+
num_pages = math.ceil(total / limit)
509+
# We already grabbed page 1 (offset 0), so fetch from page 2
510+
for page in range(1, num_pages):
511+
page_offset = page * limit
512+
page_results = self.run_query(qry, {"id": project_id, "fileLimit": limit, "fileOffset": page_offset})
513+
page_items = page_results['data']['project'].get('files', {}).get('items', [])
514+
items.extend(page_items)
515+
516+
return RiverscapesProject(project_data)
495517

496518
def get_project_files(self, project_id: str) -> List[Dict[str, any]]:
497519
""" This returns the file listing with everything you need to download project files
@@ -504,8 +526,34 @@ def get_project_files(self, project_id: str) -> List[Dict[str, any]]:
504526
_type_: _description_
505527
"""
506528
qry = self.load_query('projectFiles')
507-
results = self.run_query(qry, {"projectId": project_id})
508-
return results['data']['project']['files']
529+
530+
offset = 0
531+
limit = 500
532+
all_files = []
533+
534+
# Initial fetch
535+
results = self.run_query(qry, {
536+
"projectId": project_id,
537+
"limit": limit,
538+
"offset": offset
539+
})
540+
541+
files_meta = results['data']['project']['files']
542+
total = files_meta['total']
543+
all_files.extend(files_meta['items'])
544+
545+
if total > limit:
546+
num_pages = math.ceil(total / limit)
547+
for page in range(1, num_pages):
548+
page_offset = page * limit
549+
results = self.run_query(qry, {
550+
"projectId": project_id,
551+
"limit": limit,
552+
"offset": page_offset
553+
})
554+
all_files.extend(results['data']['project']['files']['items'])
555+
556+
return all_files
509557

510558
def get_project_types(self) -> Dict[str, RiverscapesProjectType]:
511559
"""_summary_

pydex/graphql/queries/getProjectFull.graphql

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
query getProjectFull($id: ID!) {
1+
query getProjectFull($id: ID!, $fileLimit: Int = 500, $fileOffset: Int = 0) {
22
project(id: $id) {
33
...dbobj
44
bounds {
@@ -54,10 +54,13 @@ query getProjectFull($id: ID!) {
5454
tags
5555
totalSize
5656
visibility
57-
files {
58-
localPath
59-
size
60-
contentType
57+
files(limit: $fileLimit, offset: $fileOffset) {
58+
items {
59+
localPath
60+
size
61+
contentType
62+
}
63+
...paginated
6164
}
6265
tree {
6366
defaultView
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
query projectFiles ($projectId: ID!) {
1+
query projectFiles ($projectId: ID!, $limit: Int!, $offset: Int!) {
22
project(id: $projectId) {
33
id
4-
files {
5-
size
6-
contentType
7-
downloadUrl
8-
localPath
9-
etag
4+
files(limit: $limit, offset: $offset) {
5+
total
6+
items {
7+
size
8+
contentType
9+
downloadUrl
10+
localPath
11+
etag
12+
}
1013
}
11-
id
1214
}
1315
}

pydex/graphql/riverscapes.schema.graphql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ type Project implements DBObj & HasOwner & HasStar {
11351135
deleted: Boolean!
11361136
description: String!
11371137
dirty: Boolean!
1138-
files: [FileDownloadMeta!]!
1138+
files(limit: Int!, offset: Int!): PaginatedFileDownloadMeta!
11391139

11401140
"""Banner image (optional)"""
11411141
heroImage: HeroImage
@@ -2396,6 +2396,7 @@ type User implements DBObj & UserInterface {
23962396
description: String!
23972397
hivebriteProfile: HivebriteProfile
23982398
id: ID!
2399+
initialized: Boolean
23992400
jobTitle: String
24002401
lastLogin: DateTime!
24012402
location: String
@@ -2466,6 +2467,7 @@ interface UserInterface {
24662467
description: String!
24672468
hivebriteProfile: HivebriteProfile
24682469
id: ID!
2470+
initialized: Boolean
24692471

24702472
"""Simple job title string field"""
24712473
jobTitle: String

0 commit comments

Comments
 (0)