3232# https://support.shotgunsoftware.com/forums/48807-developer-api-info
3333# ---------------------------------------------------------------------------------------------
3434
35- __version__ = "3.0.5 "
35+ __version__ = "3.0.6 "
3636
3737# ---------------------------------------------------------------------------------------------
3838# SUMMARY
5858# CHANGELOG
5959# ---------------------------------------------------------------------------------------------
6060"""
61+ +v3.0.6 - 2010 Jan 25
62+ + optimization: don't request paging_info unless required (and server support is available)
63+
6164+v3.0.5 - 2010 Dec 20
6265 + officially remove support for old api3_preview controller
6366 + find(): allow requesting a specific page of results instead of returning them all at once
@@ -192,11 +195,28 @@ def __init__(self, base_url, script_name, api_key, convert_datetimes_to_utc=True
192195
193196 self ._api3 = ShotgunCRUD (server_options )
194197
198+ self .server_info = self ._api3 .info ()
199+ self ._determine_features ()
200+
195201 self .local_path_string = None
196202 self .platform = self ._determine_platform ()
197203 if self .platform :
198204 self .local_path_string = "local_path_%s" % (self .platform )
199205
206+ def _determine_features (self ):
207+ self .supports_paging_info = False
208+
209+ if self .server_info .has_key ('version' ):
210+ v = self .server_info ['version' ]
211+ else :
212+ return
213+
214+ if v [0 ] == 2 and v [1 ] == 3 and v [2 ] >= 4 :
215+ self .supports_paging_info = True
216+ elif v [0 ] >= 2 and v [1 ] >= 4 :
217+ self .supports_paging_info = True
218+
219+
200220 def _determine_platform (self ):
201221 s = platform .system ().lower ()
202222 if s in ['windows' ,'linux' ,'darwin' ]:
@@ -365,6 +385,9 @@ def find(self, entity_type, filters, fields=None, order=None, filter_operator=No
365385 "paging" : {"entities_per_page" : self .records_per_page , "current_page" : 1 }
366386 }
367387
388+ if self .supports_paging_info :
389+ req ["return_paging_info" ] = True
390+
368391 if order :
369392 req ['sorts' ] = []
370393 for sort in order :
@@ -377,15 +400,24 @@ def find(self, entity_type, filters, fields=None, order=None, filter_operator=No
377400
378401 if type (limit ) != int or limit < 0 :
379402 raise ValueError ("find() 'limit' parameter must be a positive integer" )
380- elif (limit and limit > 0 and limit < self .records_per_page ):
403+ elif (limit and limit > 0 and limit <= self .records_per_page ):
381404 req ["paging" ]["entities_per_page" ] = limit
405+
406+ # If page isn't set and the limit doesn't require pagination, then trigger the
407+ # faster code path.
408+ if page == 0 :
409+ page = 1
382410
383411 records = []
384412
385413 # if page is specified, then only return the page of records requested
386414 if type (page ) != int or page < 0 :
387415 raise ValueError ("find() 'page' parameter must be a positive integer" )
388416 elif page != 0 :
417+ # No paging_info needed, so optimize it out.
418+ if self .supports_paging_info :
419+ req ["return_paging_info" ] = False
420+
389421 req ["paging" ]["current_page" ] = page
390422 resp = self ._api3 .read (req )
391423 results = resp ["results" ]["entities" ]
@@ -683,6 +715,14 @@ def callable(*args, **kwargs):
683715 return self .meta_caller (attr , * args , ** kwargs )
684716 return callable
685717
718+ def info (self ):
719+ try :
720+ server_info = self .__sg .info ()
721+ except :
722+ server_info = {}
723+
724+ return server_info
725+
686726 def meta_caller (self , attr , * args , ** kwargs ):
687727 try :
688728 return eval (
0 commit comments