我已经编写了从c#中的wadlogstable获取最新的诊断日志,但是它遍历所有记录,然后给出最新的条目 前。表格中有5000条记录,但我只想要最近或最近的1000条记录 ,但它在给出所有记录后,通过查询给出最后的1000条记录,所以非常耗时,fecth需要将近7-8分钟4000-5000记录如何获取最新的低于1000 WADLogsTable条目?
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ATCommon.DiagnosticConfig);
CloudTableClient cloudTableClient = storageAccount.CreateCloudTableClient();
TableServiceContext serviceContext = cloudTableClient.GetDataServiceContext();
IQueryable<WadLogEntity> traceLogsTable = serviceContext.CreateQuery<WadLogEntity>("WADLogsTable");
var selection = from row in traceLogsTable where row.PartitionKey.CompareTo("0" + DateTime.UtcNow.AddHours(hours).Ticks) >= 0 select row;
//var selection = from row in traceLogsTable where row.PartitionKey.CompareTo("0" + DateTime.UtcNow.AddMinutes(-5.0).Ticks) >= 0 select row;
CloudTableQuery<WadLogEntity> query = selection.AsTableServiceQuery<WadLogEntity>();
IEnumerable<WadLogEntity> output = query.Execute();
return output.OrderByDescending(s => s.Timestamp).ToList();
什么是您的分区密钥?你可以提供样本数据吗? – Mahesh
@Mahesh分区键是用于过滤目的,以及我在这里共享的整个代码。 –
那就是我想说的。 azure表不支持排序,所有使用分区键您需要编写逻辑以获取最新的100分区键作为索引在您的表中,因此查询将运行速度快。使用分区键过滤器,你需要像先写逻辑只获得最后2小时记录,如果你在这个查询中只有60个,再试一次,然后填写你的清单,然后按它排序,只需100 – Mahesh