예제 #1
0
파일: views.py 프로젝트: rhelmer/datazilla
def _getTestRunSummary(procPath, procName, fullProcPath, request, gm):

   productIds = [] 
   testIds = [] 
   platformIds = []

   #####
   #Calling _getIdList() insures that we have only numbers in the 
   #lists, this gaurds against SQL injection
   #####
   if 'product_ids' in request.GET:
      productIds = DatazillaModel.getIdList(request.GET['product_ids'])
   if 'test_ids' in request.GET:
      testIds = DatazillaModel.getIdList(request.GET['test_ids'])
   if 'platform_ids' in request.GET:
      platformIds = DatazillaModel.getIdList(request.GET['platform_ids'])

   if not productIds:
      ##Set default productId##
      productIds = [12]

   jsonData = '{}'
   timeKey = 'days_7'
   timeRanges = DatazillaModel.getTimeRanges()

   mc = memcache.Client([settings.DATAZILLA_MEMCACHED], debug=0)

   if productIds and (not testIds) and (not platformIds):

      if len(productIds) > 1:
         extendList = { 'data':[], 'columns':[] } 
         for id in productIds:
            key = DatazillaModel.getCacheKey(str(id), timeKey)
            compressedJsonData = mc.get(key)
            if compressedJsonData:
               jsonData = zlib.decompress( compressedJsonData )
               data = json.loads( jsonData )
               extendList['data'].extend( data['data'] )
               extendList['columns'] = data['columns']

         jsonData = json.dumps(extendList)

      else:
         key = DatazillaModel.getCacheKey(str(productIds[0]), timeKey)
         compressedJsonData = mc.get(key)

         if compressedJsonData:
            jsonData = zlib.decompress( compressedJsonData )

   else:
      table = gm.getTestRunSummary(timeRanges[timeKey]['start'], 
                                   timeRanges[timeKey]['stop'], 
                                   productIds, 
                                   platformIds, 
                                   testIds)

      jsonData = json.dumps( table )

   return jsonData
예제 #2
0
def cacheTestSummaries():

   gm = DatazillaModel('graphs.json')
   dataIter = gm.getAllSummaryCacheData()

   mc = memcache.Client([os.environ["DATAZILLA_MEMCACHED"]], debug=0)

   for d in dataIter:
      for data in d:
         key = DatazillaModel.getCacheKey( data['item_id'], data['item_data'] )
         rv = mc.set(key, zlib.compress( data['value'] ))
         if not rv:
            sys.stderr.write("ERROR: Failed to store object in memcache: %s, %s\n" % ( str(data['item_id']), data['item_data'] ) ) 

   gm.disconnect()