有没有人对这两种从 CosmosDB 检索单个对象的方法进行过分析?
container.ReadItemAsync<Device>("devices", new PartitionKey(deviceId), null, default);
VS
container.GetItemLinqQueryable<Device>(true).Where(a => a.DeviceId == deviceId).FirstOrDefault();
我的猜测是 ReadItemAsync 更快,但有人确定吗?
最佳答案
ReadItemAsync 不仅更快,而且更便宜。
ReadItem做点读操作,固定数量RUs (请求单位)基于项目的大小。如果项目大小不变,操作将始终消耗相同的 RU。
ItemLinqQueryable 执行一个查询,这将消耗更多的 RU(这些可能会有所不同),这取决于配置的索引策略。
关于azure-cosmosdb - ReadItemAsync 与 GetItemLinqQueryable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58629356/