Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
342
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
25
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
TransFem.org
Sharkey
Commits
e523e548
Commit
e523e548
authored
4 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
perf(server): Reduce database query
parent
606e5c08
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
src/models/repositories/notification.ts
+57
-10
57 additions, 10 deletions
src/models/repositories/notification.ts
src/server/api/endpoints/i/notifications.ts
+1
-1
1 addition, 1 deletion
src/server/api/endpoints/i/notifications.ts
with
58 additions
and
11 deletions
src/models/repositories/notification.ts
+
57
−
10
View file @
e523e548
import
{
EntityRepository
,
Repository
}
from
'
typeorm
'
;
import
{
Users
,
Notes
,
UserGroupInvitations
,
AccessTokens
}
from
'
..
'
;
import
{
EntityRepository
,
In
,
Repository
}
from
'
typeorm
'
;
import
{
Users
,
Notes
,
UserGroupInvitations
,
AccessTokens
,
NoteReactions
}
from
'
..
'
;
import
{
Notification
}
from
'
../entities/notification
'
;
import
{
awaitAll
}
from
'
../../prelude/await-all
'
;
import
{
SchemaType
}
from
'
../../misc/schema
'
;
import
{
Note
}
from
'
../entities/note
'
;
import
{
NoteReaction
}
from
'
../entities/note-reaction
'
;
import
{
User
}
from
'
../entities/user
'
;
export
type
PackedNotification
=
SchemaType
<
typeof
packedNotificationSchema
>
;
...
...
@@ -10,6 +13,11 @@ export type PackedNotification = SchemaType<typeof packedNotificationSchema>;
export
class
NotificationRepository
extends
Repository
<
Notification
>
{
public
async
pack
(
src
:
Notification
[
'
id
'
]
|
Notification
,
options
:
{
_hintForEachNotes_
:
{
myReactions
:
Map
<
Note
[
'
id
'
],
NoteReaction
|
null
>
;
};
}
):
Promise
<
PackedNotification
>
{
const
notification
=
typeof
src
===
'
object
'
?
src
:
await
this
.
findOneOrFail
(
src
);
const
token
=
notification
.
appAccessTokenId
?
await
AccessTokens
.
findOneOrFail
(
notification
.
appAccessTokenId
)
:
null
;
...
...
@@ -22,23 +30,41 @@ export class NotificationRepository extends Repository<Notification> {
userId
:
notification
.
notifierId
,
user
:
notification
.
notifierId
?
Users
.
pack
(
notification
.
notifier
||
notification
.
notifierId
)
:
null
,
...(
notification
.
type
===
'
mention
'
?
{
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
),
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
,
{
detail
:
true
,
_hint_
:
options
.
_hintForEachNotes_
}),
}
:
{}),
...(
notification
.
type
===
'
reply
'
?
{
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
),
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
,
{
detail
:
true
,
_hint_
:
options
.
_hintForEachNotes_
}),
}
:
{}),
...(
notification
.
type
===
'
renote
'
?
{
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
),
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
,
{
detail
:
true
,
_hint_
:
options
.
_hintForEachNotes_
}),
}
:
{}),
...(
notification
.
type
===
'
quote
'
?
{
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
),
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
,
{
detail
:
true
,
_hint_
:
options
.
_hintForEachNotes_
}),
}
:
{}),
...(
notification
.
type
===
'
reaction
'
?
{
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
),
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
,
{
detail
:
true
,
_hint_
:
options
.
_hintForEachNotes_
}),
reaction
:
notification
.
reaction
}
:
{}),
...(
notification
.
type
===
'
pollVote
'
?
{
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
),
note
:
Notes
.
pack
(
notification
.
note
||
notification
.
noteId
!
,
notification
.
notifieeId
,
{
detail
:
true
,
_hint_
:
options
.
_hintForEachNotes_
}),
choice
:
notification
.
choice
}
:
{}),
...(
notification
.
type
===
'
groupInvited
'
?
{
...
...
@@ -52,10 +78,31 @@ export class NotificationRepository extends Repository<Notification> {
});
}
public
packMany
(
public
async
packMany
(
notifications
:
Notification
[],
meId
:
User
[
'
id
'
]
)
{
return
Promise
.
all
(
notifications
.
map
(
x
=>
this
.
pack
(
x
)));
if
(
notifications
.
length
===
0
)
return
[];
const
notes
=
notifications
.
filter
(
x
=>
x
.
note
!=
null
).
map
(
x
=>
x
.
note
!
);
const
noteIds
=
notes
.
map
(
n
=>
n
.
id
);
const
myReactionsMap
=
new
Map
<
Note
[
'
id
'
],
NoteReaction
|
null
>
();
const
renoteIds
=
notes
.
filter
(
n
=>
n
.
renoteId
!=
null
).
map
(
n
=>
n
.
renoteId
!
);
const
targets
=
[...
noteIds
,
...
renoteIds
];
const
myReactions
=
await
NoteReactions
.
find
({
userId
:
meId
,
noteId
:
In
(
targets
),
});
for
(
const
target
of
targets
)
{
myReactionsMap
.
set
(
target
,
myReactions
.
find
(
reaction
=>
reaction
.
noteId
===
target
)
||
null
);
}
return
await
Promise
.
all
(
notifications
.
map
(
x
=>
this
.
pack
(
x
,
{
_hintForEachNotes_
:
{
myReactions
:
myReactionsMap
}
})));
}
}
...
...
This diff is collapsed.
Click to expand it.
src/server/api/endpoints/i/notifications.ts
+
1
−
1
View file @
e523e548
...
...
@@ -112,5 +112,5 @@ export default define(meta, async (ps, user) => {
readNotification
(
user
.
id
,
notifications
.
map
(
x
=>
x
.
id
));
}
return
await
Notifications
.
packMany
(
notifications
);
return
await
Notifications
.
packMany
(
notifications
,
user
.
id
);
});
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