Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Vidéos
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Vidéos
Commits
e4a686b4
Unverified
Commit
e4a686b4
authored
5 years ago
by
Chocobozzz
Browse files
Options
Downloads
Patches
Plain Diff
Cache some SQL queries
parent
f27a885a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/models/account/account.ts
+15
-1
15 additions, 1 deletion
server/models/account/account.ts
server/models/activitypub/actor.ts
+17
-2
17 additions, 2 deletions
server/models/activitypub/actor.ts
with
32 additions
and
3 deletions
server/models/account/account.ts
+
15
−
1
View file @
e4a686b4
...
...
@@ -27,7 +27,7 @@ import { VideoCommentModel } from '../video/video-comment'
import
{
UserModel
}
from
'
./user
'
import
{
AvatarModel
}
from
'
../avatar/avatar
'
import
{
VideoPlaylistModel
}
from
'
../video/video-playlist
'
import
{
CONSTRAINTS_FIELDS
,
WEBSERVER
}
from
'
../../initializers/constants
'
import
{
CONSTRAINTS_FIELDS
,
SERVER_ACTOR_NAME
,
WEBSERVER
}
from
'
../../initializers/constants
'
import
{
FindOptions
,
IncludeOptions
,
Op
,
Transaction
,
WhereOptions
}
from
'
sequelize
'
import
{
AccountBlocklistModel
}
from
'
./account-blocklist
'
import
{
ServerBlocklistModel
}
from
'
../server/server-blocklist
'
...
...
@@ -218,6 +218,8 @@ export class AccountModel extends Model<AccountModel> {
})
BlockedAccounts
:
AccountBlocklistModel
[]
private
static
cache
:
{
[
id
:
string
]:
any
}
=
{}
@
BeforeDestroy
static
async
sendDeleteIfOwned
(
instance
:
AccountModel
,
options
)
{
if
(
!
instance
.
Actor
)
{
...
...
@@ -245,6 +247,11 @@ export class AccountModel extends Model<AccountModel> {
}
static
loadLocalByName
(
name
:
string
):
Bluebird
<
MAccountDefault
>
{
// The server actor never change, so we can easily cache it
if
(
name
===
SERVER_ACTOR_NAME
&&
AccountModel
.
cache
[
name
])
{
return
Bluebird
.
resolve
(
AccountModel
.
cache
[
name
])
}
const
query
=
{
where
:
{
[
Op
.
or
]:
[
...
...
@@ -272,6 +279,13 @@ export class AccountModel extends Model<AccountModel> {
}
return
AccountModel
.
findOne
(
query
)
.
then
(
account
=>
{
if
(
name
===
SERVER_ACTOR_NAME
)
{
AccountModel
.
cache
[
name
]
=
account
}
return
account
})
}
static
loadByNameAndHost
(
name
:
string
,
host
:
string
):
Bluebird
<
MAccountDefault
>
{
...
...
This diff is collapsed.
Click to expand it.
server/models/activitypub/actor.ts
+
17
−
2
View file @
e4a686b4
...
...
@@ -27,7 +27,7 @@ import {
isActorPublicKeyValid
}
from
'
../../helpers/custom-validators/activitypub/actor
'
import
{
isActivityPubUrlValid
}
from
'
../../helpers/custom-validators/activitypub/misc
'
import
{
ACTIVITY_PUB
,
ACTIVITY_PUB_ACTOR_TYPES
,
CONSTRAINTS_FIELDS
,
WEBSERVER
}
from
'
../../initializers/constants
'
import
{
ACTIVITY_PUB
,
ACTIVITY_PUB_ACTOR_TYPES
,
CONSTRAINTS_FIELDS
,
SERVER_ACTOR_NAME
,
WEBSERVER
}
from
'
../../initializers/constants
'
import
{
AccountModel
}
from
'
../account/account
'
import
{
AvatarModel
}
from
'
../avatar/avatar
'
import
{
ServerModel
}
from
'
../server/server
'
...
...
@@ -276,6 +276,8 @@ export class ActorModel extends Model<ActorModel> {
})
VideoChannel
:
VideoChannelModel
private
static
cache
:
{
[
id
:
string
]:
any
}
=
{}
static
load
(
id
:
number
):
Bluebird
<
MActor
>
{
return
ActorModel
.
unscoped
().
findByPk
(
id
)
}
...
...
@@ -342,6 +344,11 @@ export class ActorModel extends Model<ActorModel> {
}
static
loadLocalByName
(
preferredUsername
:
string
,
transaction
?:
Transaction
):
Bluebird
<
MActorFull
>
{
// The server actor never change, so we can easily cache it
if
(
preferredUsername
===
SERVER_ACTOR_NAME
&&
ActorModel
.
cache
[
preferredUsername
])
{
return
Bluebird
.
resolve
(
ActorModel
.
cache
[
preferredUsername
])
}
const
query
=
{
where
:
{
preferredUsername
,
...
...
@@ -350,7 +357,15 @@ export class ActorModel extends Model<ActorModel> {
transaction
}
return
ActorModel
.
scope
(
ScopeNames
.
FULL
).
findOne
(
query
)
return
ActorModel
.
scope
(
ScopeNames
.
FULL
)
.
findOne
(
query
)
.
then
(
actor
=>
{
if
(
preferredUsername
===
SERVER_ACTOR_NAME
)
{
ActorModel
.
cache
[
preferredUsername
]
=
actor
}
return
actor
})
}
static
loadByNameAndHost
(
preferredUsername
:
string
,
host
:
string
):
Bluebird
<
MActorFull
>
{
...
...
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