diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 11a8398e..7c6b38f7 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -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 diff --git a/server/AyaNova/Controllers/AttachmentController.cs b/server/AyaNova/Controllers/AttachmentController.cs index 1cf1765f..f794e2d6 100644 --- a/server/AyaNova/Controllers/AttachmentController.cs +++ b/server/AyaNova/Controllers/AttachmentController.cs @@ -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); diff --git a/server/AyaNova/Startup.cs b/server/AyaNova/Startup.cs index 25b5cd75..cf18f927 100644 --- a/server/AyaNova/Startup.cs +++ b/server/AyaNova/Startup.cs @@ -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 diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index 03a4b15a..a231429c 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -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 { diff --git a/server/AyaNova/util/FileUtil.cs b/server/AyaNova/util/FileUtil.cs index f696e0eb..36bf29be 100644 --- a/server/AyaNova/util/FileUtil.cs +++ b/server/AyaNova/util/FileUtil.cs @@ -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; @@ -192,10 +193,10 @@ namespace AyaNova.Util //stream entry into a new jobject and add it to the list StreamReader reader = new StreamReader(entry.Open()); string text = reader.ReadToEnd(); - var j = JObject.Parse(text); - + var j = JObject.Parse(text); + //Here add v7 import file name as sometimes it's needed later (locales) - j.Add("V7_SOURCE_FILE_NAME", JToken.FromObject(importFileName)); + j.Add("V7_SOURCE_FILE_NAME", JToken.FromObject(importFileName)); jList.Add(j); } } @@ -259,7 +260,7 @@ namespace AyaNova.Util /// /// /// - internal static FileAttachment storeFileAttachment(string tempFilePath, string contentType, string fileName, AyaTypeId attachToObject, AyContext ct) + internal static async Task StoreFileAttachmentAsync(string tempFilePath, string contentType, string fileName, AyaTypeId attachToObject, AyContext ct) { //calculate hash var hash = FileHash.GetChecksum(tempFilePath); @@ -287,15 +288,15 @@ namespace AyaNova.Util { StoredFileName = hash, DisplayFileName = fileName, - Notes = string.Empty, + Notes = string.Empty, ContentType = contentType, AttachToObjectId = attachToObject.ObjectId, AttachToObjectType = attachToObject.ObjectType }; //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 /// /// /// - internal static FileAttachment deleteFileAttachment(FileAttachment fileAttachmentToBeDeleted, AyContext ct) + internal static async Task 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) {