简体   繁体   中英

Correct way to have statistics from child entities

Please help me find a way to make this efficient

The program has this entities:
Projects 1-N Modules
Modules 1-N Submodules .
Submodules 1-N Segments .
each segment has different status (default / completed) and wordcount

The wordcount is made when the segments are inserted into the database and stored in a column.

Views. Project List There should be less than 100 projects so for that im listing all of them without include's .

Module List (with parameter of 1 projectId) should have a column with words completed/total and rows completed/ total

Submodule List (with parameter of 1 moduleId) should have a column with words completed/total and rows completed/ total

Assume i would have around 50k rows (segments ) per module . so perfomance is a must.

Option 1: IQueryable Childs.Count() of some sort
Option 2: Add Stats columns to tables in database with CRON jobs to update them or to have a stored proccedure / triggers in mysql .
Option 3?: Creating 2 views in mysql? have never done them but maybe they are right for the job?
Options suggested: None yet

Have never worked with such big datasets before and performance is a must. Please advice

var query = _context.Submodules.Where(t => t.Id == id)
                    .Select(e => new Submodules{
                        Id = e.Id,
                        Name = e.Name,
                        Status = e.Status,
                        Token = e.Token,
                        ModuleId = e.ModuleId,
                        Gender = e.Gender,
                        TotalRows = e.TotalRows,
                        TotalWords = e.TotalWords,
                        CompletedWords = e.Segments.Where(a => a.Status == Abr.Recorded).Sum(y=> y.Wordcount),
                        CompletedRows = e.Segments.Where(a => a.Status == Abr.Recorded).Count()
                    }).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM