mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
query fixes for folders. denormalize userid
This commit is contained in:
parent
63e95f0f55
commit
943ef81c06
@ -148,7 +148,6 @@
|
||||
<Build Include="dbo\Stored Procedures\CipherDetails_Update.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Subvault_ReadById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_UpdateEmailPassword.sql" />
|
||||
<Build Include="dbo\Stored Procedures\FolderCipher_DeleteByUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Subvault_Update.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SubvaultUser_ReadPermissionsBySubvaultUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SubvaultCipher_Create.sql" />
|
||||
|
@ -10,6 +10,6 @@ FROM
|
||||
LEFT JOIN
|
||||
[dbo].[Favorite] F ON F.[CipherId] = C.[Id] AND F.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[FolderCipher] FC ON FC.[CipherId] = C.[Id]
|
||||
[dbo].[FolderCipher] FC ON FC.[UserId] = @UserId AND FC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[Folder] FO ON FO.[Id] = FC.[FolderId] AND FO.[UserId] = @UserId
|
||||
[dbo].[Folder] FO ON FO.[Id] = FC.[FolderId]
|
@ -7,11 +7,24 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
IF @FolderId IS NULL
|
||||
DECLARE @ExistingFolderId UNIQUEIDENTIFIER = NULL
|
||||
|
||||
SELECT TOP 1
|
||||
@ExistingFolderId = F.Id
|
||||
FROM
|
||||
[dbo].[FolderCipher] FC
|
||||
INNER JOIN
|
||||
[dbo].[Folder] F ON F.[Id] = FC.[FolderId]
|
||||
WHERE
|
||||
F.[UserId] = @UserId
|
||||
AND FC.[CipherId] = @Id
|
||||
|
||||
IF @ExistingFolderId IS NOT NULL AND (@FolderId IS NULL OR @FolderId != @ExistingFolderId)
|
||||
BEGIN
|
||||
EXEC [dbo].[FolderCipher_DeleteByUserId] @UserId, @Id
|
||||
EXEC [dbo].[FolderCipher_Delete] @ExistingFolderId, @Id
|
||||
END
|
||||
ELSE IF (SELECT COUNT(1) FROM [dbo].[FolderCipher] WHERE [FolderId] = @FolderId AND [CipherId] = @Id) = 0
|
||||
|
||||
IF @FolderId IS NOT NULL AND (@ExistingFolderId IS NULL OR @FolderId != @ExistingFolderId)
|
||||
BEGIN
|
||||
EXEC [dbo].[FolderCipher_Create] @FolderId, @Id
|
||||
END
|
||||
|
@ -1,16 +0,0 @@
|
||||
CREATE PROCEDURE [dbo].[FolderCipher_DeleteByUserId]
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@CipherId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE FC
|
||||
FROM
|
||||
[dbo].[FolderCipher] FC
|
||||
INNER JOIN
|
||||
[dbo].[Folder] F ON F.[Id] = FC.[FolderId]
|
||||
WHERE
|
||||
F.[UserId] = @UserId
|
||||
AND [CipherId] = @CipherId
|
||||
END
|
@ -1,8 +1,10 @@
|
||||
CREATE TABLE [dbo].[FolderCipher] (
|
||||
[FolderId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[CipherId] UNIQUEIDENTIFIER NOT NULL,
|
||||
CONSTRAINT [PK_FolderCipher] PRIMARY KEY CLUSTERED ([FolderId] ASC, [CipherId] ASC),
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
CONSTRAINT [PK_FolderCipher] PRIMARY KEY CLUSTERED ([UserId] ASC, [FolderId] ASC, [CipherId] ASC),
|
||||
CONSTRAINT [FK_FolderCipher_Cipher] FOREIGN KEY ([CipherId]) REFERENCES [dbo].[Cipher] ([Id]) ON DELETE CASCADE,
|
||||
CONSTRAINT [FK_FolderCipher_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]) ON DELETE CASCADE,
|
||||
CONSTRAINT [FK_FolderCipher_Folder] FOREIGN KEY ([FolderId]) REFERENCES [dbo].[Folder] ([Id])
|
||||
);
|
||||
|
||||
|
@ -25,7 +25,8 @@ GO
|
||||
CREATE TABLE [dbo].[FolderCipher] (
|
||||
[FolderId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[CipherId] UNIQUEIDENTIFIER NOT NULL,
|
||||
CONSTRAINT [PK_FolderCipher] PRIMARY KEY CLUSTERED ([FolderId] ASC, [CipherId] ASC)
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
CONSTRAINT [PK_FolderCipher] PRIMARY KEY CLUSTERED ([UserId] ASC, [FolderId] ASC, [CipherId] ASC)
|
||||
)
|
||||
GO
|
||||
|
||||
|
@ -6,7 +6,7 @@ from cipher
|
||||
where [type] = 0
|
||||
|
||||
insert into foldercipher
|
||||
select FolderId, Id
|
||||
select FolderId, Id, UserId
|
||||
from cipher
|
||||
where [FolderId] is not null
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user