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
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()