1
0
mirror of https://github.com/bitwarden/server synced 2025-12-26 05:03:18 +00:00

put joins in tvf

This commit is contained in:
jaasen-livefront
2025-11-17 18:01:59 -08:00
parent 5e8f1f134b
commit da0131c552
6 changed files with 56 additions and 162 deletions

View File

@@ -27,6 +27,10 @@ SELECT
END [FolderId],
C.[DeletedDate],
C.[Reprompt],
C.[Key]
C.[Key],
CA.[ArchivedDate]
FROM
[dbo].[Cipher] C
LEFT JOIN [dbo].[CipherArchive] CA
ON CA.[CipherId] = C.[Id]
AND CA.[UserId] = @UserId;

View File

@@ -23,6 +23,7 @@ SELECT
C.Favorite,
C.FolderId,
C.DeletedDate,
C.ArchivedDate,
C.Reprompt,
C.[Key],
CASE
@@ -79,6 +80,7 @@ SELECT
C.Favorite,
C.FolderId,
C.DeletedDate,
C.ArchivedDate,
C.Reprompt,
C.[Key],
1 [Edit],
@@ -88,4 +90,4 @@ SELECT
FROM
[dbo].[CipherDetails](@UserId) AS C
WHERE
C.[UserId] = @UserId;
C.[UserId] = @UserId;

View File

@@ -6,44 +6,42 @@ BEGIN
SET NOCOUNT ON;
SELECT
ucd.Id,
ucd.UserId,
ucd.OrganizationId,
ucd.Type,
ucd.Data,
ucd.Attachments,
ucd.CreationDate,
ucd.RevisionDate,
ucd.Favorite,
ucd.FolderId,
ucd.DeletedDate,
ucd.Reprompt,
ucd.[Key],
ucd.OrganizationUseTotp,
MAX(ca.ArchivedDate) AS ArchivedDate,
MAX(ucd.Edit) AS Edit,
MAX(ucd.ViewPassword) AS ViewPassword,
MAX(ucd.Manage) AS Manage
[Id],
[UserId],
[OrganizationId],
[Type],
[Data],
[Attachments],
[CreationDate],
[RevisionDate],
[Favorite],
[FolderId],
[DeletedDate],
[Reprompt],
[Key],
[OrganizationUseTotp],
[ArchivedDate],
MAX([Edit]) AS Edit,
MAX([ViewPassword]) AS ViewPassword,
MAX([Manage]) AS Manage
FROM
[dbo].[UserCipherDetails](@UserId) AS ucd
LEFT JOIN [dbo].[CipherArchive] AS ca
ON ca.CipherId = ucd.Id
AND ca.UserId = @UserId
[dbo].[UserCipherDetails](@UserId)
WHERE
ucd.Id = @Id
[Id] = @Id
GROUP BY
ucd.Id,
ucd.UserId,
ucd.OrganizationId,
ucd.Type,
ucd.Data,
ucd.Attachments,
ucd.CreationDate,
ucd.RevisionDate,
ucd.Favorite,
ucd.FolderId,
ucd.DeletedDate,
ucd.Reprompt,
ucd.[Key],
ucd.OrganizationUseTotp;
[Id],
[UserId],
[OrganizationId],
[Type],
[Data],
[Attachments],
[CreationDate],
[RevisionDate],
[Favorite],
[FolderId],
[DeletedDate],
[Reprompt],
[Key],
[OrganizationUseTotp],
[ArchivedDate]
END

View File

@@ -5,11 +5,7 @@ BEGIN
SET NOCOUNT ON
SELECT
c.*,
ca.ArchivedDate
c.*
FROM
[dbo].[UserCipherDetails](@UserId) AS c
LEFT JOIN [dbo].[CipherArchive] AS ca
ON ca.CipherId = c.Id
AND ca.UserId = @UserId
END

View File

@@ -5,17 +5,13 @@ BEGIN
SET NOCOUNT ON
SELECT
c.*,
*,
1 [Edit],
1 [ViewPassword],
1 [Manage],
0 [OrganizationUseTotp],
ca.ArchivedDate
0 [OrganizationUseTotp]
FROM
[dbo].[CipherDetails](@UserId) AS c
LEFT JOIN [dbo].[CipherArchive] AS ca
ON ca.CipherId = c.Id
AND ca.UserId = @UserId
[dbo].[CipherDetails](@UserId)
WHERE
c.[UserId] = @UserId
[UserId] = @UserId
END