Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Vaultwarden
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Vaultwarden
Commits
e197f372
Unverified
Commit
e197f372
authored
6 years ago
by
Daniel García
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #314 from mprasil/find_by_user_uuid
Rewrite find_by_user_uuid to use one query
parents
9f0357ce
8451a70d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/db/models/collection.rs
+20
-19
20 additions, 19 deletions
src/db/models/collection.rs
with
20 additions
and
19 deletions
src/db/models/collection.rs
+
20
−
19
View file @
e197f372
...
@@ -79,25 +79,26 @@ impl Collection {
...
@@ -79,25 +79,26 @@ impl Collection {
}
}
pub
fn
find_by_user_uuid
(
user_uuid
:
&
str
,
conn
:
&
DbConn
)
->
Vec
<
Self
>
{
pub
fn
find_by_user_uuid
(
user_uuid
:
&
str
,
conn
:
&
DbConn
)
->
Vec
<
Self
>
{
let
mut
all_access_collections
=
users_organizations
::
table
collections
::
table
.filter
(
users_organizations
::
user_uuid
.eq
(
user_uuid
))
.left_join
(
users_collections
::
table
.on
(
.filter
(
users_organizations
::
status
.eq
(
UserOrgStatus
::
Confirmed
as
i32
))
users_collections
::
collection_uuid
.eq
(
collections
::
uuid
)
.and
(
.filter
(
users_organizations
::
access_all
.eq
(
true
))
users_collections
::
user_uuid
.eq
(
user_uuid
)
.inner_join
(
collections
::
table
.on
(
collections
::
org_uuid
.eq
(
users_organizations
::
org_uuid
)))
)
.select
(
collections
::
all_columns
)
))
.load
::
<
Self
>
(
&**
conn
)
.expect
(
"Error loading collections"
);
.left_join
(
users_organizations
::
table
.on
(
collections
::
org_uuid
.eq
(
users_organizations
::
org_uuid
)
.and
(
let
mut
assigned_collections
=
users_collections
::
table
.inner_join
(
collections
::
table
)
users_organizations
::
user_uuid
.eq
(
user_uuid
)
.left_join
(
users_organizations
::
table
.on
(
)
users_collections
::
user_uuid
.eq
(
users_organizations
::
user_uuid
)
))
))
.filter
(
.filter
(
users_collections
::
user_uuid
.eq
(
user_uuid
))
users_organizations
::
status
.eq
(
UserOrgStatus
::
Confirmed
as
i32
)
.filter
(
users_organizations
::
status
.eq
(
UserOrgStatus
::
Confirmed
as
i32
))
)
.select
(
collections
::
all_columns
)
.filter
(
.load
::
<
Self
>
(
&**
conn
)
.expect
(
"Error loading collections"
);
users_collections
::
user_uuid
.eq
(
user_uuid
)
.or
(
// Directly accessed collection
users_organizations
::
access_all
.eq
(
true
)
// access_all in Organization
all_access_collections
.append
(
&
mut
assigned_collections
);
)
all_access_collections
)
.select
(
collections
::
all_columns
)
.load
::
<
Self
>
(
&**
conn
)
.expect
(
"Error loading collections"
)
}
}
pub
fn
find_by_organization_and_user_uuid
(
org_uuid
:
&
str
,
user_uuid
:
&
str
,
conn
:
&
DbConn
)
->
Vec
<
Self
>
{
pub
fn
find_by_organization_and_user_uuid
(
org_uuid
:
&
str
,
user_uuid
:
&
str
,
conn
:
&
DbConn
)
->
Vec
<
Self
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment