From 54760bfabb36c96f666ca7f77028d0d6a9c812fc Mon Sep 17 00:00:00 2001 From: vnugent Date: Wed, 14 Feb 2024 14:35:03 -0500 Subject: Squashed commit of the following: commit d72bd53e20770be4ced0d627567ecf567d1ce9f4 Author: vnugent Date: Mon Feb 12 18:34:52 2024 -0500 refactor: #1 convert sql libraries to assets for better code splitting commit 736b873e32447254b3aadbb5c6252818c25e8fd4 Author: vnugent Date: Sun Feb 4 01:30:25 2024 -0500 submit pending changes --- .../src/Storage/LWStorageManager.cs | 37 +++++----------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'lib/VNLib.Plugins.Extensions.Data/src/Storage/LWStorageManager.cs') diff --git a/lib/VNLib.Plugins.Extensions.Data/src/Storage/LWStorageManager.cs b/lib/VNLib.Plugins.Extensions.Data/src/Storage/LWStorageManager.cs index bc506c7..f098def 100644 --- a/lib/VNLib.Plugins.Extensions.Data/src/Storage/LWStorageManager.cs +++ b/lib/VNLib.Plugins.Extensions.Data/src/Storage/LWStorageManager.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2023 Vaughn Nugent +* Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.Data @@ -32,8 +32,6 @@ using Microsoft.EntityFrameworkCore; using VNLib.Utils; using VNLib.Utils.Async; -using VNLib.Plugins.Extensions.Data.Extensions; - namespace VNLib.Plugins.Extensions.Data.Storage { @@ -78,10 +76,7 @@ namespace VNLib.Plugins.Extensions.Data.Storage /// public async Task CreateDescriptorAsync(string userId, string? descriptorIdOverride = null, CancellationToken cancellation = default) { - if (string.IsNullOrWhiteSpace(userId)) - { - throw new ArgumentNullException(nameof(userId)); - } + ArgumentException.ThrowIfNullOrWhiteSpace(userId); //If no override id was specified, generate a new one descriptorIdOverride ??= NewDescriptorIdGenerator(); @@ -89,7 +84,6 @@ namespace VNLib.Plugins.Extensions.Data.Storage DateTime createdOrModifedTime = DateTime.UtcNow; await using LWStorageContext ctx = GetContext(); - await ctx.OpenTransactionAsync(cancellation); //Make sure the descriptor doesnt exist only by its descriptor id if (await ctx.Descriptors.AnyAsync(d => d.Id == descriptorIdOverride, cancellation)) @@ -129,16 +123,11 @@ namespace VNLib.Plugins.Extensions.Data.Storage /// public async Task GetDescriptorFromUIDAsync(string userid, CancellationToken cancellation = default) { - //Allow null/empty entrys to just return null - if (string.IsNullOrWhiteSpace(userid)) - { - throw new ArgumentNullException(nameof(userid)); - } + ArgumentException.ThrowIfNullOrWhiteSpace(userid); //Init db - await using LWStorageContext db = GetContext(); - //Begin transaction - await db.OpenTransactionAsync(cancellation); + await using LWStorageContext db = GetContext(); + //Get entry LWStorageEntry? entry = await (from s in db.Descriptors where s.UserId == userid @@ -161,16 +150,11 @@ namespace VNLib.Plugins.Extensions.Data.Storage /// public async Task GetDescriptorFromIDAsync(string descriptorId, CancellationToken cancellation = default) { - //Allow null/empty entrys to just return null - if (string.IsNullOrWhiteSpace(descriptorId)) - { - throw new ArgumentNullException(nameof(descriptorId)); - } + ArgumentException.ThrowIfNullOrWhiteSpace(descriptorId); //Init db - await using LWStorageContext db = GetContext(); - //Begin transaction - await db.OpenTransactionAsync(cancellation); + await using LWStorageContext db = GetContext(); + //Get entry LWStorageEntry? entry = await (from s in db.Descriptors where s.Id == descriptorId @@ -201,8 +185,6 @@ namespace VNLib.Plugins.Extensions.Data.Storage { //Init db await using LWStorageContext db = GetContext(); - //Begin transaction - await db.OpenTransactionAsync(cancellation); //Get all expired entires LWStorageEntry[] expired = await (from s in db.Descriptors @@ -224,7 +206,6 @@ namespace VNLib.Plugins.Extensions.Data.Storage try { await using LWStorageContext ctx = GetContext(); - await ctx.OpenTransactionAsync(System.Transactions.IsolationLevel.RepeatableRead, cancellation); //Begin tracking ctx.Descriptors.Attach(entry); @@ -254,8 +235,6 @@ namespace VNLib.Plugins.Extensions.Data.Storage { //Init db await using LWStorageContext db = GetContext(); - //Begin transaction - await db.OpenTransactionAsync(cancellation); //Delete the user from the database db.Descriptors.Remove(descriptor); -- cgit