Skip to content

Commit b4c86c2

Browse files
authored
Merge pull request #448 from classtranscribe/AddIncludes
UpdateRelatedEntitiyLoading
2 parents d4c3160 + 7e35718 commit b4c86c2

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

ClassTranscribeServer/Controllers/MediaController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public MediaController(IAuthorizationService authorizationService,
4040
[HttpGet("{id}")]
4141
public async Task<ActionResult<MediaDTO>> GetMedia(string id)
4242
{
43-
var media = await _context.Medias.FindAsync(id);
43+
var media = await _context.Medias.
44+
Include(m => m.Video).ThenInclude(v => v.Transcriptions).
45+
Where(m => m.Id == id).FirstOrDefaultAsync();
4446

4547
if (media == null)
4648
{

ClassTranscribeServer/Controllers/PlaylistsController.cs

+9
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ public async Task<ActionResult<IEnumerable<PlaylistDTO>>> GetPlaylists2(string o
133133
}
134134

135135
var playLists = await _context.Playlists
136+
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.Transcriptions)
137+
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.ProcessedVideo1)
138+
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.ProcessedVideo2)
139+
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.Video1)
140+
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.Video2)
141+
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.ASLVideo)
142+
136143
.Where(p => p.OfferingId == offeringId)
137144
.OrderBy(p => p.Index)
138145
.ThenBy(p => p.CreatedAt).ToListAsync();
@@ -216,6 +223,8 @@ public async Task<ActionResult<IEnumerable<MediaSearchDTO>>> SearchForMedia(stri
216223
public async Task<ActionResult<PlaylistDTO>> GetPlaylist(string id)
217224
{
218225
var p = await _context.Playlists.FindAsync(id);
226+
// Media are explicitly loaded below, so LoadAsync is not needed
227+
219228
var user = await _userUtils.GetUser(User);
220229
if (p == null)
221230
{

ClassTranscribeServer/Utils/Authorization.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext
8484
}
8585
else if (offering != null && offering.AccessType == AccessTypes.UniversityOnly && user != null)
8686
{
87-
var universityId = await _ctDbContext.CourseOfferings.Where(co => co.OfferingId == offering.Id)
87+
var universityId = await _ctDbContext.CourseOfferings
88+
.Include(co=>co.Course).ThenInclude(c=>c.Department)
89+
.Where(co => co.OfferingId == offering.Id)
8890
.Select(c => c.Course.Department.UniversityId).FirstAsync();
8991
if (user.UniversityId == universityId)
9092
{

TaskEngine/Tasks/DescribeVideoTask.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
using ClassTranscribeDatabase;
2-
using ClassTranscribeDatabase.Models;
3-
using ClassTranscribeDatabase.Services;using Microsoft.Extensions.Logging;
4-
using Newtonsoft.Json.Linq;
5-
using System.Collections.Generic;
1+
using System.Collections.Generic;
62
using System.Diagnostics.CodeAnalysis;
73
using System;
84
using System.Linq;
95
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Logging;
7+
using Microsoft.EntityFrameworkCore;
8+
using Newtonsoft.Json.Linq;
9+
using ClassTranscribeDatabase;
10+
using ClassTranscribeDatabase.Models;
11+
using ClassTranscribeDatabase.Services;
1012
using static ClassTranscribeDatabase.CommonUtils;
1113

1214

@@ -35,13 +37,14 @@ protected async override Task OnConsume(string videoId, TaskParameters taskParam
3537

3638
using var _context = CTDbContext.CreateDbContext();
3739
Video video = await _context.Videos.FindAsync(videoId);
38-
40+
3941
if (!video.HasSceneObjectData())
4042
{
4143
GetLogger().LogInformation($"Describe Video {videoId}: Early return - no scene data to process");
4244
return;
4345
}
4446
TextData td = await _context.TextData.FindAsync(video.SceneObjectDataId);
47+
await _context.Transcriptions.Where(t => t.VideoId == videoId).LoadAsync();
4548

4649
JObject sceneData = td.GetAsJSON() as JObject;
4750
JArray scenes = sceneData["Scenes"] as JArray;

TaskEngine/Tasks/DownloadMediaTask.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected override async Task OnConsume(string mediaId, TaskParameters taskParam
5252
media = await _context.Medias.Where(m => m.Id == mediaId)
5353
.Include(m => m.Playlist).FirstAsync();
5454
GetLogger().LogInformation($"Downloading media id=({media.Id}), UniqueMediaIdentifier={media.UniqueMediaIdentifier}");
55-
subdir = ToCourseOfferingSubDirectory(_context, media); // e.g. "/data/2203-abcd"
55+
subdir = ToCourseOfferingSubDirectory(_context, media.Playlist); // e.g. "/data/2203-abcd"
5656
}
5757
Video video = new Video();
5858
switch (media.SourceType)
@@ -72,7 +72,14 @@ protected override async Task OnConsume(string mediaId, TaskParameters taskParam
7272

7373
using (var _context = CTDbContext.CreateDbContext())
7474
{
75-
var latestMedia = await _context.Medias.FindAsync(media.Id);
75+
var latestMedia = await _context.Medias
76+
.Include(m=>m.Video).ThenInclude(v=>v.Video2)
77+
.Include(m=>m.Video).ThenInclude(v=>v.Video1)
78+
.FirstOrDefaultAsync(m => m.Id==media.Id); // Find does not support Include
79+
if(latestMedia == null) { // should never happen...
80+
GetLogger().LogInformation($"Media ({media.Id}): latestMedia == null !?");
81+
return;
82+
}
7683
GetLogger().LogInformation($"Media ({media.Id}): latestMedia.Video == null is {latestMedia.Video == null}");
7784

7885
// Don't add video if there are already videos for the given media.

0 commit comments

Comments
 (0)