From 81d2e3e6088d775106e74ef698863fb0f82f791a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 26 Oct 2017 20:55:35 -0400 Subject: [PATCH] delete with recompile --- .../Stored Procedures/Cipher_DeleteById.sql | 1 + .../2017-10-25_00_OrgUserUpdates.sql | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/Sql/dbo/Stored Procedures/Cipher_DeleteById.sql b/src/Sql/dbo/Stored Procedures/Cipher_DeleteById.sql index a13aae6ae..6d5a3628e 100644 --- a/src/Sql/dbo/Stored Procedures/Cipher_DeleteById.sql +++ b/src/Sql/dbo/Stored Procedures/Cipher_DeleteById.sql @@ -1,5 +1,6 @@ CREATE PROCEDURE [dbo].[Cipher_DeleteById] @Id UNIQUEIDENTIFIER +WITH RECOMPILE AS BEGIN SET NOCOUNT ON diff --git a/util/Setup/DbScripts/2017-10-25_00_OrgUserUpdates.sql b/util/Setup/DbScripts/2017-10-25_00_OrgUserUpdates.sql index b4a1b4d34..ee36150c4 100644 --- a/util/Setup/DbScripts/2017-10-25_00_OrgUserUpdates.sql +++ b/util/Setup/DbScripts/2017-10-25_00_OrgUserUpdates.sql @@ -330,3 +330,54 @@ BEGIN EXEC [dbo].[User_BumpAccountRevisionDate] @UserId END GO + +IF OBJECT_ID('[dbo].[Cipher_DeleteById]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[Cipher_DeleteById] +END +GO + +CREATE PROCEDURE [dbo].[Cipher_DeleteById] + @Id UNIQUEIDENTIFIER +WITH RECOMPILE +AS +BEGIN + SET NOCOUNT ON + + DECLARE @UserId UNIQUEIDENTIFIER + DECLARE @OrganizationId UNIQUEIDENTIFIER + DECLARE @Attachments BIT + + SELECT TOP 1 + @UserId = [UserId], + @OrganizationId = [OrganizationId], + @Attachments = CASE WHEN [Attachments] IS NOT NULL THEN 1 ELSE 0 END + FROM + [dbo].[Cipher] + WHERE + [Id] = @Id + + DELETE + FROM + [dbo].[Cipher] + WHERE + [Id] = @Id + + IF @OrganizationId IS NOT NULL + BEGIN + IF @Attachments = 1 + BEGIN + EXEC [dbo].[Organization_UpdateStorage] @OrganizationId + END + EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId + END + ELSE IF @UserId IS NOT NULL + BEGIN + IF @Attachments = 1 + BEGIN + EXEC [dbo].[User_UpdateStorage] @UserId + END + EXEC [dbo].[User_BumpAccountRevisionDate] @UserId + END +END +GO