Skip to content

Commit f75e8c4

Browse files
authored
Merge pull request #2146 from TechnologyEnhancedLearning/Develop/Fixes/TD-937-FixSlowCourseUsageReportResponse
TD-937 Groups data returned from DB by date to reduce number of rows retrieved
2 parents 4e4d9fb + 676d901 commit f75e8c4

File tree

8 files changed

+48
-42
lines changed

8 files changed

+48
-42
lines changed

DigitalLearningSolutions.Data.Tests/DataServices/ActivityDataServiceTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public void GetFilteredActivity_gets_expected_activity()
3333
// when
3434
var result = service.GetFilteredActivity(
3535
101,
36-
DateTime.Parse("2014-01-01 00:00:00.000"),
37-
DateTime.Parse("2014-01-31 23:59:59.999"),
36+
DateTime.Parse("2014-01-01"),
37+
DateTime.Parse("2014-01-31"),
3838
null,
3939
null,
4040
null
@@ -48,22 +48,22 @@ public void GetFilteredActivity_gets_expected_activity()
4848
result.Count().Should().Be(9);
4949

5050
var first = result.First();
51-
first.LogDate.Should().Be(DateTime.Parse("2014-01-08 11:04:35.753"));
51+
first.LogDate.Should().Be(DateTime.Parse("2014-01-08"));
5252
first.LogYear.Should().Be(2014);
5353
first.LogQuarter.Should().Be(1);
5454
first.LogMonth.Should().Be(1);
55-
first.Completed.Should().BeFalse();
56-
first.Evaluated.Should().BeFalse();
57-
first.Registered.Should().BeTrue();
55+
first.Completed.Should().Equals(0);
56+
first.Evaluated.Should().Equals(0);
57+
first.Registered.Should().Equals(1);
5858

5959
var last = result.Last();
60-
last.LogDate.Should().Be(DateTime.Parse("2014-01-31 09:43:28.840"));
60+
last.LogDate.Should().Be(DateTime.Parse("2014-01-31"));
6161
last.LogYear.Should().Be(2014);
6262
last.LogQuarter.Should().Be(1);
6363
last.LogMonth.Should().Be(1);
64-
last.Completed.Should().BeFalse();
65-
last.Evaluated.Should().BeFalse();
66-
last.Registered.Should().BeTrue();
64+
last.Completed.Should().Equals(0);
65+
last.Evaluated.Should().Equals(0);
66+
last.Registered.Should().Equals(1);
6767
}
6868
}
6969

DigitalLearningSolutions.Data/DataServices/ActivityDataService.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public IEnumerable<ActivityLog> GetFilteredActivity(
4040
{
4141
return connection.Query<ActivityLog>(
4242
@"SELECT
43-
LogDate,
43+
Cast(LogDate As Date) As LogDate,
4444
LogYear,
4545
LogQuarter,
4646
LogMonth,
47-
Registered,
48-
Completed,
49-
Evaluated
47+
SUM(CAST(Registered AS Int)) AS Registered,
48+
SUM(CAST(Completed AS Int)) AS Completed,
49+
SUM(CAST(Evaluated AS Int)) AS Evaluated
5050
FROM tActivityLog AS al
5151
WHERE (LogDate >= @startDate
5252
AND (@endDate IS NULL OR LogDate <= @endDate)
@@ -59,7 +59,10 @@ AND EXISTS (
5959
SELECT ap.ApplicationID
6060
FROM Applications ap
6161
WHERE ap.ApplicationID = al.ApplicationID
62-
AND ap.DefaultContentTypeID <> 4)",
62+
AND ap.DefaultContentTypeID <> 4)
63+
GROUP BY Cast(LogDate As Date), LogYear,
64+
LogQuarter,
65+
LogMonth",
6366
new
6467
{
6568
centreId,

DigitalLearningSolutions.Data/DataServices/PlatformReportsDataService.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class PlatformReportsDataService : IPlatformReportsDataService
4141
{
4242
private readonly IDbConnection connection;
4343
private readonly ILogger<PlatformReportsDataService> logger;
44-
private readonly string selectSelfAssessmentActivity = @"SELECT al.ActivityDate, al.Enrolled, al.Submitted | al.SignedOff AS Completed
44+
private readonly string selectSelfAssessmentActivity = @"SELECT Cast(al.ActivityDate As Date) As ActivityDate, SUM(CAST(al.Enrolled AS Int)) AS Enrolled, SUM(CAST((al.Submitted | al.SignedOff) AS Int)) AS Completed
4545
FROM ReportSelfAssessmentActivityLog AS al WITH (NOLOCK) INNER JOIN
4646
Centres AS ce WITH (NOLOCK) ON al.CentreID = ce.CentreID INNER JOIN
4747
SelfAssessments AS sa WITH (NOLOCK) ON sa.ID = al.SelfAssessmentID
@@ -116,7 +116,7 @@ public IEnumerable<SelfAssessmentActivity> GetSelfAssessmentActivity(
116116
{
117117
var whereClause = GetSelfAssessmentWhereClause(supervised);
118118
return connection.Query<SelfAssessmentActivity>(
119-
$@"{selectSelfAssessmentActivity} AND {whereClause}",
119+
$@"{selectSelfAssessmentActivity} AND {whereClause} GROUP BY Cast(al.ActivityDate As Date)",
120120
new
121121
{
122122
centreId,
@@ -157,13 +157,13 @@ public IEnumerable<ActivityLog> GetFilteredCourseActivity(
157157
{
158158
return connection.Query<ActivityLog>(
159159
@"SELECT
160-
LogDate,
161-
LogYear,
160+
Cast(LogDate As Date) As LogDate,
161+
LogYear,
162162
LogQuarter,
163163
LogMonth,
164-
Registered,
165-
Completed,
166-
Evaluated
164+
SUM(CAST(Registered AS Int)) AS Registered,
165+
SUM(CAST(Completed AS Int)) AS Completed,
166+
SUM(CAST(Evaluated AS Int)) AS Evaluated
167167
FROM tActivityLog AS al WITH(NOLOCK) INNER JOIN
168168
Applications AS ap WITH(NOLOCK) ON ap.ApplicationID = al.ApplicationID INNER JOIN
169169
Centres AS ce WITH(NOLOCK) ON al.CentreID = ce.CentreID
@@ -178,7 +178,10 @@ Centres AS ce WITH(NOLOCK) ON al.CentreID = ce.CentreID
178178
AND (@centreTypeID IS NULL OR ce.CentreTypeID = @centreTypeID)
179179
AND (@brandId IS NULL OR al.BrandID = @brandId)
180180
AND (al.Registered = 1 OR al.Completed = 1 OR al.Evaluated = 1)
181-
AND (@coreContent IS NULL OR ap.CoreContent = @coreContent)",
181+
AND (@coreContent IS NULL OR ap.CoreContent = @coreContent)
182+
GROUP BY Cast(LogDate As Date), LogYear,
183+
LogQuarter,
184+
LogMonth",
182185
new
183186
{
184187
centreId,

DigitalLearningSolutions.Data/Models/PlatformReports/SelfAssessmentActivity.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
public class SelfAssessmentActivity
55
{
66
public DateTime ActivityDate { get; set; }
7-
public bool Enrolled { get; set; }
8-
public bool Completed { get; set; }
7+
public int Enrolled { get; set; }
8+
public int Completed { get; set; }
99
}
1010
}

DigitalLearningSolutions.Data/Models/TrackingSystem/ActivityLog.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ public class ActivityLog
88
public int LogYear { get; set; }
99
public int LogQuarter { get; set; }
1010
public int LogMonth { get; set; }
11-
public bool Registered { get; set; }
12-
public bool Completed { get; set; }
13-
public bool Evaluated { get; set; }
11+
public int Registered { get; set; }
12+
public int Completed { get; set; }
13+
public int Evaluated { get; set; }
1414
}
1515
}

DigitalLearningSolutions.Web.Tests/Services/ActivityServiceTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ string expectedLogDateForCompletion
8282
{
8383
new ActivityLog
8484
{
85-
Completed = true,
86-
Evaluated = false,
87-
Registered = false,
85+
Completed = 1,
86+
Evaluated = 0,
87+
Registered = 0,
8888
LogDate = DateTime.Parse("2015-12-22"),
8989
LogYear = 2015,
9090
LogQuarter = 4,
@@ -575,9 +575,9 @@ private void GivenActivityDataServiceReturnsDataInExampleSheet()
575575
{
576576
new ActivityLog
577577
{
578-
Completed = true,
579-
Evaluated = false,
580-
Registered = false,
578+
Completed = 1,
579+
Evaluated = 0,
580+
Registered = 0,
581581
LogDate = DateTime.Parse("2020-12-22"),
582582
LogYear = 2020,
583583
LogQuarter = 4,

DigitalLearningSolutions.Web/Services/ActivityService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ ReportInterval interval
201201
new DateTime(groupingOfLogs.Key),
202202
interval
203203
),
204-
groupingOfLogs.Count(activityLog => activityLog.Registered),
205-
groupingOfLogs.Count(activityLog => activityLog.Completed),
206-
groupingOfLogs.Count(activityLog => activityLog.Evaluated)
204+
groupingOfLogs.Sum(activityLog => activityLog.Registered),
205+
groupingOfLogs.Sum(activityLog => activityLog.Completed),
206+
groupingOfLogs.Sum(activityLog => activityLog.Evaluated)
207207
)
208208
);
209209
}

DigitalLearningSolutions.Web/Services/PlatformReportService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ ReportInterval interval
9797
new DateTime(groupingOfLogs.Key),
9898
interval
9999
),
100-
groupingOfLogs.Count(activityLog => activityLog.Enrolled),
101-
groupingOfLogs.Count(activityLog => activityLog.Completed)
100+
groupingOfLogs.Sum(activityLog => activityLog.Enrolled),
101+
groupingOfLogs.Sum(activityLog => activityLog.Completed)
102102
)
103103
);
104104
}
@@ -172,9 +172,9 @@ ReportInterval interval
172172
new DateTime(groupingOfLogs.Key),
173173
interval
174174
),
175-
groupingOfLogs.Count(activityLog => activityLog.Registered),
176-
groupingOfLogs.Count(activityLog => activityLog.Completed),
177-
groupingOfLogs.Count(activityLog => activityLog.Evaluated)
175+
groupingOfLogs.Sum(activityLog => activityLog.Registered),
176+
groupingOfLogs.Sum(activityLog => activityLog.Completed),
177+
groupingOfLogs.Sum(activityLog => activityLog.Evaluated)
178178
)
179179
);
180180
}

0 commit comments

Comments
 (0)