Skip to content

Commit

Permalink
Fix #308 - Remove useless pages in table queries
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Mar 3, 2022
1 parent 835112d commit f3d4920
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace AzureIoTHub.Portal.Server.Controllers.v10

[Route("/api/settings/device-tags")]
[ApiController]

[ApiVersion("1.0")]
[Produces("application/json")]
[ApiExplorerSettings(GroupName = "Portal Settings")]
Expand Down Expand Up @@ -62,17 +62,13 @@ public async Task<IActionResult> Post(List<DeviceTag> tags)
{
var query = this.tableClientFactory
.GetDeviceTagSettings()
.Query<TableEntity>()
.AsPages();
.Query<TableEntity>();

foreach (var page in query)
foreach (var item in query)
{
foreach (var item in page.Values)
{
await this.tableClientFactory
.GetDeviceTagSettings()
.DeleteEntityAsync(item.PartitionKey, item.RowKey);
}
await this.tableClientFactory
.GetDeviceTagSettings()
.DeleteEntityAsync(item.PartitionKey, item.RowKey);
}

foreach (DeviceTag tag in tags)
Expand All @@ -94,13 +90,13 @@ await this.tableClientFactory
[HttpGet(Name = "GET a set of device settings")]
public ActionResult<List<DeviceTag>> Get()
{
var query = this.tableClientFactory
.GetDeviceTagSettings()
.Query<TableEntity>();
var query = this.tableClientFactory
.GetDeviceTagSettings()
.Query<TableEntity>();

var tagList = query.Select(this.deviceTagMapper.GetDeviceTag);
var tagList = query.Select(this.deviceTagMapper.GetDeviceTag);

return this.Ok(tagList.ToList());
return this.Ok(tagList.ToList());
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task<IActionResult> Post(string id, DeviceModelCommand[] commands)
{
try
{
var query = this.tableClientFactory
var templateQuery = this.tableClientFactory
.GetDeviceTemplates()
.GetEntity<TableEntity>(LoRaWANDeviceModelsController.DefaultPartitionKey, id);
}
Expand All @@ -83,19 +83,15 @@ public async Task<IActionResult> Post(string id, DeviceModelCommand[] commands)
throw;
}

var pages = this.tableClientFactory
var query = this.tableClientFactory
.GetDeviceCommands()
.Query<TableEntity>(filter: $"PartitionKey eq '{id}'")
.AsPages();
.Query<TableEntity>(filter: $"PartitionKey eq '{id}'");

foreach (var page in pages)
foreach (var item in query)
{
foreach (var item in page.Values)
{
await this.tableClientFactory
.GetDeviceCommands()
.DeleteEntityAsync(item.PartitionKey, item.RowKey);
}
await this.tableClientFactory
.GetDeviceCommands()
.DeleteEntityAsync(item.PartitionKey, item.RowKey);
}

foreach (var command in commands)
Expand Down Expand Up @@ -128,7 +124,7 @@ public ActionResult<DeviceModelCommand[]> Get(string id)
{
try
{
var query = this.tableClientFactory
var templateQuery = this.tableClientFactory
.GetDeviceTemplates()
.GetEntity<TableEntity>(LoRaWANDeviceModelsController.DefaultPartitionKey, id);
}
Expand All @@ -144,16 +140,16 @@ public ActionResult<DeviceModelCommand[]> Get(string id)
throw;
}

var pages = this.tableClientFactory
var query = this.tableClientFactory
.GetDeviceCommands()
.Query<TableEntity>(filter: $"PartitionKey eq '{id}'")
.AsPages();
.Query<TableEntity>(filter: $"PartitionKey eq '{id}'");

var commands = new List<DeviceModelCommand>();

foreach (var page in pages)
foreach (var item in query)
{
commands.AddRange(page.Values.Select(this.deviceModelCommandMapper.GetDeviceModelCommand));
var command = this.deviceModelCommandMapper.GetDeviceModelCommand(item);
commands.Add(command);
}

return this.Ok(commands);
Expand Down

0 comments on commit f3d4920

Please sign in to comment.