Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dima Krasner
Sharkey
Commits
2d196b67
Commit
2d196b67
authored
3 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
Update search-by-username-and-host.ts
parent
0cc055de
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/server/api/endpoints/users/search-by-username-and-host.ts
+46
-25
46 additions, 25 deletions
...server/api/endpoints/users/search-by-username-and-host.ts
with
46 additions
and
25 deletions
src/server/api/endpoints/users/search-by-username-and-host.ts
+
46
−
25
View file @
2d196b67
import
$
from
'
cafy
'
;
import
define
from
'
../../define
'
;
import
{
Users
}
from
'
@/models/index
'
;
import
{
Followings
,
Users
}
from
'
@/models/index
'
;
import
{
Brackets
}
from
'
typeorm
'
;
import
{
USER_ACTIVE_THRESHOLD
}
from
'
@/const
'
;
import
{
User
}
from
'
@/models/entities/user
'
;
export
const
meta
=
{
tags
:
[
'
users
'
],
...
...
@@ -18,11 +19,6 @@ export const meta = {
validator
:
$
.
optional
.
nullable
.
str
,
},
offset
:
{
validator
:
$
.
optional
.
num
.
min
(
0
),
default
:
0
,
},
limit
:
{
validator
:
$
.
optional
.
num
.
range
(
1
,
100
),
default
:
10
,
...
...
@@ -60,34 +56,59 @@ export default define(meta, async (ps, me) => {
q
.
andWhere
(
'
user.updatedAt IS NOT NULL
'
);
q
.
orderBy
(
'
user.updatedAt
'
,
'
DESC
'
);
const
users
=
await
q
.
take
(
ps
.
limit
!
).
skip
(
ps
.
offset
).
getMany
();
const
users
=
await
q
.
take
(
ps
.
limit
!
).
getMany
();
return
await
Users
.
packMany
(
users
,
me
,
{
detail
:
ps
.
detail
});
}
else
if
(
ps
.
username
)
{
let
users
=
await
Users
.
createQueryBuilder
(
'
user
'
)
.
where
(
'
user.host IS NULL
'
)
.
andWhere
(
'
user.isSuspended = FALSE
'
)
.
andWhere
(
'
user.usernameLower LIKE :username
'
,
{
username
:
ps
.
username
.
toLowerCase
()
+
'
%
'
})
.
andWhere
(
new
Brackets
(
qb
=>
{
qb
.
where
(
'
user.updatedAt IS NULL
'
)
.
orWhere
(
'
user.updatedAt > :activeThreshold
'
,
{
activeThreshold
:
activeThreshold
});
}))
.
orderBy
(
'
user.updatedAt
'
,
'
DESC
'
,
'
NULLS LAST
'
)
.
take
(
ps
.
limit
!
)
.
skip
(
ps
.
offset
)
.
getMany
();
if
(
users
.
length
<
ps
.
limit
!
)
{
const
otherUsers
=
await
Users
.
createQueryBuilder
(
'
user
'
)
.
where
(
'
user.host IS NOT NULL
'
)
let
users
:
User
[]
=
[];
if
(
me
)
{
const
followingQuery
=
Followings
.
createQueryBuilder
(
'
following
'
)
.
select
(
'
following.followeeId
'
)
.
where
(
'
following.followerId = :followerId
'
,
{
followerId
:
me
.
id
});
const
query
=
Users
.
createQueryBuilder
(
'
user
'
)
.
where
(
`user.id IN (
${
followingQuery
.
getQuery
()
}
)`
)
.
andWhere
(
`user.id != :meId`
,
{
meId
:
me
.
id
})
.
andWhere
(
'
user.isSuspended = FALSE
'
)
.
andWhere
(
'
user.usernameLower LIKE :username
'
,
{
username
:
ps
.
username
.
toLowerCase
()
+
'
%
'
})
.
andWhere
(
new
Brackets
(
qb
=>
{
qb
.
where
(
'
user.updatedAt IS NULL
'
)
.
orWhere
(
'
user.updatedAt > :activeThreshold
'
,
{
activeThreshold
:
activeThreshold
});
}));
query
.
setParameters
(
followingQuery
.
getParameters
());
users
=
await
query
.
orderBy
(
'
user.usernameLower
'
,
'
ASC
'
)
.
take
(
ps
.
limit
!
)
.
getMany
();
if
(
users
.
length
<
ps
.
limit
!
)
{
const
otherQuery
=
await
Users
.
createQueryBuilder
(
'
user
'
)
.
where
(
`user.id NOT IN (
${
followingQuery
.
getQuery
()
}
)`
)
.
andWhere
(
`user.id != :meId`
,
{
meId
:
me
.
id
})
.
andWhere
(
'
user.isSuspended = FALSE
'
)
.
andWhere
(
'
user.usernameLower LIKE :username
'
,
{
username
:
ps
.
username
.
toLowerCase
()
+
'
%
'
})
.
andWhere
(
'
user.updatedAt IS NOT NULL
'
);
otherQuery
.
setParameters
(
followingQuery
.
getParameters
());
const
otherUsers
=
await
otherQuery
.
orderBy
(
'
user.updatedAt
'
,
'
DESC
'
)
.
take
(
ps
.
limit
!
-
users
.
length
)
.
getMany
();
users
=
users
.
concat
(
otherUsers
);
}
}
else
{
users
=
await
Users
.
createQueryBuilder
(
'
user
'
)
.
where
(
'
user.isSuspended = FALSE
'
)
.
andWhere
(
'
user.usernameLower LIKE :username
'
,
{
username
:
ps
.
username
.
toLowerCase
()
+
'
%
'
})
.
andWhere
(
'
user.updatedAt IS NOT NULL
'
)
.
orderBy
(
'
user.updatedAt
'
,
'
DESC
'
)
.
take
(
ps
.
limit
!
-
users
.
length
)
.
getMany
();
users
=
users
.
concat
(
otherUsers
);
}
return
await
Users
.
packMany
(
users
,
me
,
{
detail
:
ps
.
detail
});
...
...
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