簡體   English   中英

如何獲取最新的1000 WADLogsTable條目以下?

[英]How to fetch latest below 1000 WADLogsTable entry?

我已經為從c#中的wadlogstable獲取最新診斷日志進行了編碼,但是它遍歷了所有記錄,然后給出了最新的ex。 表中有5000條記錄,但是我只希望最新或最后1000條記錄,但是它給出了所有記錄,然后在通過查詢進行排序后給出了最后1000條記錄,因此這非常耗時,要花費近7-8分鍾才能影響4,000 -5000條記錄

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

您可以嘗試通過技巧來實現它,使用DateTime.MaxValue.Ticks – DateTime.UtcNow.Ticks的RowKey值,以允許您按照從新項目到舊項目的偏移時間對項目進行排序。 這樣,您可以按正確的順序或首先添加的最新項檢索結果,然后使用.Take(1000)參數將結果限制為最近的1000行。 此博客中查看詳細信息。

我的參賽作品超過5億。 並每秒增加更多。

string apiLogTableName = "yourtableName";
StorageTable apiLogsTable = new StorageTable(apiLogTableName);

 string filter1 = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, date);   //hear you can check with ticks


 string filter2 = TableQuery.GenerateFilterConditionForInt("yourColumn", QueryComparisons.Equal, yourValue);

            string filter3 = TableQuery.GenerateFilterCondition("YourColumn2", QueryComparisons.NotEqual, "YourValue2");



            TableQuery<ApiCallLogEntity> findapiLogsRecord = new TableQuery<ApiCallLogEntity>().Where(TableQuery.CombineFilters(

                TableQuery.CombineFilters(
                            filter1,
                            TableOperators.And,
                            filter2),
                TableOperators.And, filter3));

//you can use
//var records= apiLogsTable._table.ExecuteQuery(findapiLogsRecord)


//bellow code will get one-one records // time consuming
            foreach (ApiCallLogEntity entity in apiLogsTable._table.ExecuteQuery(findapiLogsRecord))
            {
                Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
                    entity.Action, entity.RequestBody);


                tw.WriteLine("{0}, {1}\t{2}\t{3}\t{4}", entity.PartitionKey, entity.RowKey,
                    entity.Action, entity.RequestBody, entity.ResponseBody);
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM