def GET(self, jrequest, jresponse): LIMIT = 100 assert isinstance(jrequest, JsonRpcRequest) assert isinstance(jresponse, JsonRpcResponse) jresponse.setId() try: start = int(jrequest.getValue("start")[0]) end = int(jrequest.getValue("end")[0]) except: jresponse.setError(JsonRpcError.INVALID_PARAMS, "start and end are mandatory") return query = Data.queryRange(start, end) keys = query.fetch(keys_only=True, limit=LIMIT) for key in keys: data = key.get() assert isinstance(data, Data) query_for_duplicated_data = data.queryDuplication() assert isinstance(query_for_duplicated_data, ndb.Query) keys_for_duplicated_data = query_for_duplicated_data.fetch( keys_only=True) if len(keys_for_duplicated_data) <= 1: continue jresponse.addResult([ data.dataId, data.field, data.string, getCanonicalData(key).get().dataId ]) jresponse.setExtraValue("limit", LIMIT)
def eliminateUnusedData(self): query = Data.queryRange(self.currentDataId, self.end) for data_key in query.iter(keys_only=True): data = data_key.get() if data: self.currentDataId = data_key.get().dataId metadata_query = Metadata.queryByData(data_key) metadata_key = metadata_query.get(keys_only=True) if metadata_key: continue #info("deleting data_key=%s (data_id = %s)" % (data_key, data_key.get().dataId)) self.nDeleted += 1 data_key.delete()
def GET(self, jrequest, jresponse): assert isinstance(jresponse, JsonRpcResponse) jresponse.setId() path_info = self.request.path_info.split("/") start = int(path_info[3]) end = int(path_info[4]) query = Data.queryRange(start, end) #query = query.filter(Data.dataId >= start) #query = query.filter(Data.dataId <= end) keys = query.fetch(keys_only=True) for key in keys: entity = key.get() assert isinstance(entity, Data) jresponse.addResult(entity)
def GET(self, jrequest, jresponse): LIMIT = 100 assert isinstance(jrequest, JsonRpcRequest) assert isinstance(jresponse, JsonRpcResponse) jresponse.setId() try: start = int(jrequest.getValue("start")[0]) end = int(jrequest.getValue("end")[0]) except: jresponse.setError(JsonRpcError.INVALID_PARAMS, "start and end are mandatory") return query = Data.queryRange(start, end) keys = query.fetch(keys_only=True, limit=LIMIT) for key in keys: data = key.get() assert isinstance(data, Data) query_for_duplicated_data = data.queryDuplication() assert isinstance(query_for_duplicated_data, ndb.Query) keys_for_duplicated_data = query_for_duplicated_data.fetch(keys_only=True) if len(keys_for_duplicated_data) <= 1: continue jresponse.addResult([data.dataId, data.field, data.string, getCanonicalData(key).get().dataId]) jresponse.setExtraValue("limit", LIMIT)
def delete_data(start, end): query = DataNdb.queryRange(start, end) keys = query.fetch(keys_only=True) for key in keys: key.delete()