This commit is contained in:
2020-01-28 00:55:31 +00:00
parent 6e2c00acc2
commit 6a682a6475
5 changed files with 15 additions and 22 deletions

View File

@@ -7,9 +7,6 @@ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOiIxNTcxODU5OTU0IiwiZXhwIjoiMTU3MjQ
TODO: Look at any of my middleware code as it's a HOT PATH, make sure it's async db access etc and nothing slowing it down
TODO: Any code at the server that access the db or does file IO MUST be async top to bottom!!
- FileUtil may have a bunch of IO stuff

View File

@@ -222,7 +222,7 @@ namespace AyaNova.Api.Controllers
{
foreach (UploadedFileInfo a in uploadFormData.UploadedFiles)
{
var v = FileUtil.storeFileAttachment(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, attachToObject, ct);
var v = await FileUtil.StoreFileAttachmentAsync(a.InitialUploadedPathName, a.MimeType, a.OriginalFileName, attachToObject, ct);
returnList.Add(new NameIdItem()
{
Name = v.DisplayFileName,
@@ -300,7 +300,7 @@ namespace AyaNova.Api.Controllers
//do the delete
//this handles removing the file if there are no refs left and also the db record for the attachment
FileUtil.deleteFileAttachment(dbObj, ct);
await FileUtil.DeleteFileAttachmentAsync(dbObj, ct);
//Event log process delete
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, dbObj.AttachToObjectId, dbObj.AttachToObjectType, AyaEvent.AttachmentDelete, dbObj.DisplayFileName), ct);

View File

@@ -450,7 +450,7 @@ namespace AyaNova
{
AyaNova.Core.License.FetchKeyAsync(apiServerState, dbContext, _newLog).Wait();
//NOTE: For unit testing make sure the time zone in util is set to the same figure as here to ensure list filter by date tests will work because server is on same page as user in terms of time
Util.Seeder.SeedDatabaseAsync(Util.Seeder.SeedLevel.SmallOneManShopTrialDataSet, -7).Wait();//#############################################################################################
Util.Seeder.SeedDatabaseAsync(Util.Seeder.SeedLevel.HugeForLoadTest, -7).Wait();//#############################################################################################
}
//TESTING
#endif

View File

@@ -1,15 +1,10 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.JsonPatch;
using Newtonsoft.Json.Linq;
using EnumsNET;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Models;
using System.Collections.Generic;
using AyaNova.DataList;
namespace AyaNova.Biz
{

View File

@@ -1,8 +1,9 @@
using System;
using System.Threading.Tasks;
using System.IO;
using System.IO.Compression;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using AyaNova.Models;
using AyaNova.Biz;
@@ -259,7 +260,7 @@ namespace AyaNova.Util
/// <param name="attachToObject"></param>
/// <param name="ct"></param>
/// <returns></returns>
internal static FileAttachment storeFileAttachment(string tempFilePath, string contentType, string fileName, AyaTypeId attachToObject, AyContext ct)
internal static async Task<FileAttachment> StoreFileAttachmentAsync(string tempFilePath, string contentType, string fileName, AyaTypeId attachToObject, AyContext ct)
{
//calculate hash
var hash = FileHash.GetChecksum(tempFilePath);
@@ -294,8 +295,8 @@ namespace AyaNova.Util
};
//Store in DB
ct.FileAttachment.Add(fi);
ct.SaveChanges();
await ct.FileAttachment.AddAsync(fi);
await ct.SaveChangesAsync();
//Return AyFileInfo object
return fi;
@@ -333,15 +334,15 @@ namespace AyaNova.Util
/// <param name="fileAttachmentToBeDeleted"></param>
/// <param name="ct"></param>
/// <returns></returns>
internal static FileAttachment deleteFileAttachment(FileAttachment fileAttachmentToBeDeleted, AyContext ct)
internal static async Task<FileAttachment> DeleteFileAttachmentAsync(FileAttachment fileAttachmentToBeDeleted, AyContext ct)
{
//check ref count of file
var count = ct.FileAttachment.Count(w => w.StoredFileName == fileAttachmentToBeDeleted.StoredFileName);
var count = await ct.FileAttachment.LongCountAsync(w => w.StoredFileName == fileAttachmentToBeDeleted.StoredFileName);
//Store in DB
ct.FileAttachment.Remove(fileAttachmentToBeDeleted);
ct.SaveChanges();
await ct.SaveChangesAsync();
if (count < 2)
{