物联网平台CockroachDB子查询统计设备数量点相关代码修改,将内部子查询替换为外部循环统计

Former-commit-id: 1bd43fc08f23bd4d4d08a10cdaa1a347982bbac6
TangShanKaiPing
wanggang 5 years ago
parent 8ecf8e58f7
commit f9b140b050

Binary file not shown.

Binary file not shown.

@ -18,14 +18,17 @@ namespace UserCenter.Controllers
private readonly IConfiguration _cfg;
private readonly IRepository<Node> _nodeRepo;
private readonly IRepository<NodeCategory> _nodeCategoryRepo;
private readonly IRepository<Device> _deviceRepo;
public NodeController(IConfiguration cfg,
IRepository<Node> nodeRepo,
IRepository<NodeCategory> nodeCategoryRepo)
IRepository<NodeCategory> nodeCategoryRepo,
IRepository<Device> deviceRepo)
{
this._cfg = cfg;
this._nodeRepo = nodeRepo;
this._nodeCategoryRepo = nodeCategoryRepo;
this._deviceRepo = deviceRepo;
}
[HttpPost]
@ -34,6 +37,7 @@ namespace UserCenter.Controllers
try
{
var model = this._nodeRepo.ReadOnlyTable()
.ToList()
.Select(o => new
{
o.Id,
@ -41,7 +45,7 @@ namespace UserCenter.Controllers
o.Number,
o.Image,
o.DisplayOrder,
Count = o.Devices.Count()
Count = _deviceRepo.ReadOnlyTable().Count(d => d.NodeId == o.Id)
});
return Ok(model);
}

@ -35,6 +35,7 @@ namespace UserCenter.Controllers
{
var model = this._productRepo.ReadOnlyTable()
.OrderBy(o => o.DisplayOrder)
.ToList()
.Select(o => new
{
o.Id,
@ -42,7 +43,7 @@ namespace UserCenter.Controllers
o.Number,
o.Image,
o.DisplayOrder,
Count = o.Devices.Count()
Count = _deviceRepo.ReadOnlyTable().Count(d => d.ProductId == o.Id)
});
return Ok(model);
}

@ -13,41 +13,49 @@ namespace IoTCenter.Areas.Admin.Controllers
{
private readonly IRepository<Node> _nodeRepo;
private readonly IRepository<Product> _productRepo;
private readonly IRepository<Device> _deviceRepo;
private readonly IRepository<Category> _categoryRepo;
public HomeController(IRepository<Node> nodeRepo, IRepository<Category> categoryRepo, IRepository<Product> productRepo)
public HomeController(IRepository<Node> nodeRepo, IRepository<Category> categoryRepo, IRepository<Product> productRepo, IRepository<Device> deviceRepo)
{
this._nodeRepo = nodeRepo;
this._categoryRepo = categoryRepo;
this._productRepo = productRepo;
this._deviceRepo = deviceRepo;
}
public IActionResult Index()
{
var model = new HomeIndexViewModel
{
Nodes = this._nodeRepo.ReadOnlyTable().Select(o => new NodeViewModel
Nodes = this._nodeRepo.ReadOnlyTable()
.ToList()
.Select(o => new NodeViewModel
{
Id = o.Id,
Number = o.Number,
Name = o.Name,
Image = o.Image,
DeviceCount = o.Devices.Count()
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.NodeId == o.Id)
}).ToList(),
Categories = this._categoryRepo.ReadOnlyTable().Select(o => new CategoryViewModel
Categories = this._categoryRepo.ReadOnlyTable()
.ToList()
.Select(o => new CategoryViewModel
{
Id = o.Id,
Name = o.Name,
Image = o.Image,
Number = o.Number,
DeviceCount = o.Products.SelectMany(o => o.Devices).Count()
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.Product.CategoryId == o.Id)
}).ToList(),
Products = this._productRepo.ReadOnlyTable().Select(o => new ProductViewModel
Products = this._productRepo.ReadOnlyTable()
.ToList()
.Select(o => new ProductViewModel
{
Id = o.Id,
Name = o.Name,
Image = o.Image,
DeviceCount = o.Devices.Count()
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.ProductId == o.Id)
}).ToList()
};
return View(model);

@ -92,6 +92,7 @@ namespace IoTCenter.Controllers
.Include(o => o.Scenes)
.OrderBy(o => o.DisplayOrder)
.ThenBy(o => o.Name)
.ToList()
.Select(o => new
{
o.Id,
@ -100,7 +101,7 @@ namespace IoTCenter.Controllers
o.Image,
o.DisplayOrder,
o.Scenes,
DeviceCount = o.Devices.Count()
DeviceCount = this._deviceRepo.ReadOnlyTable().Count(d => d.NodeId == o.Id)
})
.ToList();
return Json(model);

@ -12,7 +12,7 @@
"redis": "127.0.0.1:6379,allowAdmin=true"
},
"AppSettings": {
"database": "sqlite",
"database": "postgresql",
"UseCookieSessionStore": false
}
}
Loading…
Cancel
Save