1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Removed tracking of cached objects when possible

This commit is contained in:
Uncled1023 2022-05-29 15:25:01 -07:00
parent 399cca937e
commit 88fb168044
3 changed files with 21 additions and 9 deletions

View File

@ -136,7 +136,7 @@ namespace Teknik.Areas.Paste
using (TeknikEntities db = new TeknikEntities(optionsBuilder.Options))
{
var paste = GetPaste(db, cache, url);
var paste = GetPaste(db, cache, url, false);
if (paste != null)
{
paste.Views++;
@ -149,9 +149,15 @@ namespace Teknik.Areas.Paste
public static Models.Paste GetPaste(TeknikEntities db, ObjectCache cache, string url)
{
var paste = cache.AddOrGetObject(url, (key) => db.Pastes.FirstOrDefault(up => up.Url == key));
return GetPaste(db, cache, url, true);
}
if (paste != null &&
public static Models.Paste GetPaste(TeknikEntities db, ObjectCache cache, string url, bool attach)
{
var paste = cache.AddOrGetObject(url, (key) => db.Pastes.AsNoTracking().FirstOrDefault(up => up.Url == key));
if (attach &&
paste != null &&
!db.Exists(paste))
db.Attach(paste);

View File

@ -228,7 +228,7 @@ namespace Teknik.Areas.Upload.Controllers
long contentLength = 0;
DateTime dateUploaded = new DateTime();
var upload = UploadHelper.GetUpload(_dbContext, _cache, file);
var upload = UploadHelper.GetUpload(_dbContext, _cache, file, false);
if (upload != null)
{
// Check Expiration
@ -416,7 +416,7 @@ namespace Teknik.Areas.Upload.Controllers
{
if (_config.UploadConfig.DownloadEnabled)
{
Models.Upload upload = UploadHelper.GetUpload(_dbContext, _cache, file);
Models.Upload upload = UploadHelper.GetUpload(_dbContext, _cache, file, false);
if (upload != null)
{
// Check Expiration
@ -460,7 +460,7 @@ namespace Teknik.Areas.Upload.Controllers
public IActionResult DeleteByKey(string file, string key)
{
ViewBag.Title = "File Delete | " + file ;
Models.Upload upload = UploadHelper.GetUpload(_dbContext, _cache, file);
Models.Upload upload = UploadHelper.GetUpload(_dbContext, _cache, file, false);
if (upload != null)
{
DeleteViewModel model = new DeleteViewModel();

View File

@ -160,7 +160,7 @@ namespace Teknik.Areas.Upload
using (TeknikEntities db = new TeknikEntities(optionsBuilder.Options))
{
var upload = GetUpload(db, cache, url);
var upload = GetUpload(db, cache, url, false);
if (upload != null)
{
upload.Downloads++;
@ -173,9 +173,15 @@ namespace Teknik.Areas.Upload
public static Models.Upload GetUpload(TeknikEntities db, ObjectCache cache, string url)
{
var upload = cache.AddOrGetObject(url, (key) => db.Uploads.FirstOrDefault(up => up.Url == key));
return GetUpload(db, cache, url, true);
}
if (upload != null &&
public static Models.Upload GetUpload(TeknikEntities db, ObjectCache cache, string url, bool attach)
{
var upload = cache.AddOrGetObject(url, (key) => db.Uploads.AsNoTracking().FirstOrDefault(up => up.Url == key));
if (attach &&
upload != null &&
!db.Exists(upload))
db.Attach(upload);