[csw-devel] SF.net SVN: gar:[20540] csw/mgar/gar/v2/lib/web/pkgdb_web.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Fri Mar 29 21:44:39 CET 2013


Revision: 20540
          http://gar.svn.sourceforge.net/gar/?rev=20540&view=rev
Author:   wahwah
Date:     2013-03-29 20:44:39 +0000 (Fri, 29 Mar 2013)
Log Message:
-----------
pkgdb: Don't recode JSON when not needed

This is potentially a big time saver. When retrieving data from the database
and serving over HTTP in JSON, we can just send the data as they are without
recoding.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/web/pkgdb_web.py

Modified: csw/mgar/gar/v2/lib/web/pkgdb_web.py
===================================================================
--- csw/mgar/gar/v2/lib/web/pkgdb_web.py	2013-03-29 20:44:29 UTC (rev 20539)
+++ csw/mgar/gar/v2/lib/web/pkgdb_web.py	2013-03-29 20:44:39 UTC (rev 20540)
@@ -386,9 +386,13 @@
       pkg = models.Srv4FileStats.selectBy(md5_sum=md5_sum).getOne()
     except sqlobject.main.SQLObjectNotFound, e:
       raise web.notfound()
-    data_structure = pkg.GetStatsStruct()
     web.header('Content-type', 'application/x-vnd.opencsw.pkg;type=pkg-stats')
-    return json.dumps(data_structure, cls=PkgStatsEncoder)
+    if pkg.data_obj_mimetype == 'application/json':
+      # If data are in JSON already, we can send them without decoding.
+      return pkg.data_obj.pickle
+    else:
+      data_structure = pkg.GetStatsStruct()
+      return json.dumps(data_structure, cls=PkgStatsEncoder)
 
 
 class Srv4ByCatAndCatalogname(object):

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list