Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateRelatedEntitiyLoading #448

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ClassTranscribeServer/Controllers/MediaController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public MediaController(IAuthorizationService authorizationService,
[HttpGet("{id}")]
public async Task<ActionResult<MediaDTO>> GetMedia(string id)
{
var media = await _context.Medias.FindAsync(id);
var media = await _context.Medias.
Include(m => m.Video).ThenInclude(v => v.Transcriptions).
Where(m => m.Id == id).FirstOrDefaultAsync();

if (media == null)
{
Expand Down
9 changes: 9 additions & 0 deletions ClassTranscribeServer/Controllers/PlaylistsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ public async Task<ActionResult<IEnumerable<PlaylistDTO>>> GetPlaylists2(string o
}

var playLists = await _context.Playlists
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.Transcriptions)
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.ProcessedVideo1)
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.ProcessedVideo2)
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.Video1)
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.Video2)
.Include(p=>p.Medias).ThenInclude(m=>m.Video).ThenInclude(v=>v.ASLVideo)

.Where(p => p.OfferingId == offeringId)
.OrderBy(p => p.Index)
.ThenBy(p => p.CreatedAt).ToListAsync();
Expand Down Expand Up @@ -216,6 +223,8 @@ public async Task<ActionResult<IEnumerable<MediaSearchDTO>>> SearchForMedia(stri
public async Task<ActionResult<PlaylistDTO>> GetPlaylist(string id)
{
var p = await _context.Playlists.FindAsync(id);
// Media are explicitly loaded below, so LoadAsync is not needed

var user = await _userUtils.GetUser(User);
if (p == null)
{
Expand Down
4 changes: 3 additions & 1 deletion ClassTranscribeServer/Utils/Authorization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext
}
else if (offering != null && offering.AccessType == AccessTypes.UniversityOnly && user != null)
{
var universityId = await _ctDbContext.CourseOfferings.Where(co => co.OfferingId == offering.Id)
var universityId = await _ctDbContext.CourseOfferings
.Include(co=>co.Course).ThenInclude(c=>c.Department)
.Where(co => co.OfferingId == offering.Id)
.Select(c => c.Course.Department.UniversityId).FirstAsync();
if (user.UniversityId == universityId)
{
Expand Down
15 changes: 9 additions & 6 deletions TaskEngine/Tasks/DescribeVideoTask.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using ClassTranscribeDatabase;
using ClassTranscribeDatabase.Models;
using ClassTranscribeDatabase.Services;using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using ClassTranscribeDatabase;
using ClassTranscribeDatabase.Models;
using ClassTranscribeDatabase.Services;
using static ClassTranscribeDatabase.CommonUtils;


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

using var _context = CTDbContext.CreateDbContext();
Video video = await _context.Videos.FindAsync(videoId);

if (!video.HasSceneObjectData())
{
GetLogger().LogInformation($"Describe Video {videoId}: Early return - no scene data to process");
return;
}
TextData td = await _context.TextData.FindAsync(video.SceneObjectDataId);
await _context.Transcriptions.Where(t => t.VideoId == videoId).LoadAsync();

JObject sceneData = td.GetAsJSON() as JObject;
JArray scenes = sceneData["Scenes"] as JArray;
Expand Down
11 changes: 9 additions & 2 deletions TaskEngine/Tasks/DownloadMediaTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override async Task OnConsume(string mediaId, TaskParameters taskParam
media = await _context.Medias.Where(m => m.Id == mediaId)
.Include(m => m.Playlist).FirstAsync();
GetLogger().LogInformation($"Downloading media id=({media.Id}), UniqueMediaIdentifier={media.UniqueMediaIdentifier}");
subdir = ToCourseOfferingSubDirectory(_context, media); // e.g. "/data/2203-abcd"
subdir = ToCourseOfferingSubDirectory(_context, media.Playlist); // e.g. "/data/2203-abcd"
}
Video video = new Video();
switch (media.SourceType)
Expand All @@ -72,7 +72,14 @@ protected override async Task OnConsume(string mediaId, TaskParameters taskParam

using (var _context = CTDbContext.CreateDbContext())
{
var latestMedia = await _context.Medias.FindAsync(media.Id);
var latestMedia = await _context.Medias
.Include(m=>m.Video).ThenInclude(v=>v.Video2)
.Include(m=>m.Video).ThenInclude(v=>v.Video1)
.FirstOrDefaultAsync(m => m.Id==media.Id); // Find does not support Include
if(latestMedia == null) { // should never happen...
GetLogger().LogInformation($"Media ({media.Id}): latestMedia == null !?");
return;
}
GetLogger().LogInformation($"Media ({media.Id}): latestMedia.Video == null is {latestMedia.Video == null}");

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