mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: optimize token.getRecent
This commit is contained in:
1 parent
50b8343ad9
commit
2c3fd7364a
3 files changed
+5
-6
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.24.3",
|
"version": "2.24.4",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import moment from 'moment-timezone';
|
|||||||
import {
|
import {
|
||||||
UserAlreadyExistError, InvalidTokenError, VerifyPasswordError,
|
UserAlreadyExistError, InvalidTokenError, VerifyPasswordError,
|
||||||
UserNotFoundError, SystemError, BlacklistedError,
|
UserNotFoundError, SystemError, BlacklistedError,
|
||||||
UserFacingError, LoginError, NotFoundError,
|
UserFacingError, LoginError,
|
||||||
} from '../error';
|
} from '../error';
|
||||||
import { User } from '../interface';
|
import { User } from '../interface';
|
||||||
import {
|
import {
|
||||||
@@ -178,7 +178,7 @@ class UserLostPassWithCodeHandler extends Handler {
|
|||||||
class UserDetailHandler extends Handler {
|
class UserDetailHandler extends Handler {
|
||||||
@param('uid', Types.Int)
|
@param('uid', Types.Int)
|
||||||
async get(domainId: string, uid: number) {
|
async get(domainId: string, uid: number) {
|
||||||
if (uid === 0) throw new NotFoundError(this.request.path);
|
if (uid === 0) throw new UserNotFoundError(0);
|
||||||
const isSelfProfile = this.user._id === uid;
|
const isSelfProfile = this.user._id === uid;
|
||||||
const udoc = await user.getById(domainId, uid);
|
const udoc = await user.getById(domainId, uid);
|
||||||
if (!udoc) throw new UserNotFoundError(uid);
|
if (!udoc) throw new UserNotFoundError(uid);
|
||||||
|
|||||||
@@ -78,13 +78,12 @@ class TokenModel {
|
|||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static getSessionListByUid(uid: number) {
|
static getSessionListByUid(uid: number) {
|
||||||
return TokenModel.coll.find({ uid, tokenType: TokenModel.TYPE_SESSION }).sort('updateAt', -1).toArray();
|
return TokenModel.coll.find({ uid, tokenType: TokenModel.TYPE_SESSION }).sort('updateAt', -1).limit(100).toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async getMostRecentSessionByUid(uid: number) {
|
static async getMostRecentSessionByUid(uid: number) {
|
||||||
const res = await TokenModel.coll.find({ uid, tokenType: TokenModel.TYPE_SESSION }).sort('updateAt', -1).toArray();
|
return await TokenModel.coll.findOne({ uid, tokenType: TokenModel.TYPE_SESSION }, { sort: { updateAt: -1 } });
|
||||||
return res[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
|
|||||||
Reference in new issue
Block a user