Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
337
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
65e7204e
Commit
65e7204e
authored
4 years ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
perf: myReaction の取得をまとめて行うように
Related #6813
parent
0b5e3a93
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/note.ts
+43
-4
43 additions, 4 deletions
src/models/repositories/note.ts
src/services/note/reaction/create.ts
+1
-0
1 addition, 0 deletions
src/services/note/reaction/create.ts
with
44 additions
and
4 deletions
src/models/repositories/note.ts
+
43
−
4
View file @
65e7204e
...
...
@@ -9,6 +9,7 @@ import { toString } from '../../mfm/to-string';
import
{
parse
}
from
'
../../mfm/parse
'
;
import
{
Emoji
}
from
'
../entities/emoji
'
;
import
{
concat
}
from
'
../../prelude/array
'
;
import
{
NoteReaction
}
from
'
../entities/note-reaction
'
;
export
type
PackedNote
=
SchemaType
<
typeof
packedNoteSchema
>
;
...
...
@@ -83,6 +84,9 @@ export class NoteRepository extends Repository<Note> {
options
?:
{
detail
?:
boolean
;
skipHide
?:
boolean
;
_hint_
?:
{
myReactions
:
Map
<
Note
[
'
id
'
],
NoteReaction
|
null
>
;
};
}
):
Promise
<
PackedNote
>
{
const
opts
=
Object
.
assign
({
...
...
@@ -188,6 +192,16 @@ export class NoteRepository extends Repository<Note> {
}
async
function
populateMyReaction
()
{
if
(
options
?.
_hint_
?.
myReactions
)
{
const
reaction
=
options
.
_hint_
.
myReactions
.
get
(
note
.
id
);
if
(
reaction
)
{
return
convertLegacyReaction
(
reaction
.
reaction
);
}
else
if
(
reaction
===
null
)
{
return
undefined
;
}
// 実装上抜けがあるだけかもしれないので、「ヒントに含まれてなかったら(=undefinedなら)return」のようにはしない
}
const
reaction
=
await
NoteReactions
.
findOne
({
userId
:
meId
!
,
noteId
:
note
.
id
,
...
...
@@ -245,11 +259,13 @@ export class NoteRepository extends Repository<Note> {
...(
opts
.
detail
?
{
reply
:
note
.
replyId
?
this
.
pack
(
note
.
replyId
,
meId
,
{
detail
:
false
detail
:
false
,
_hint_
:
options
?.
_hint_
})
:
undefined
,
renote
:
note
.
renoteId
?
this
.
pack
(
note
.
renoteId
,
meId
,
{
detail
:
true
detail
:
true
,
_hint_
:
options
?.
_hint_
})
:
undefined
,
poll
:
note
.
hasPoll
?
populatePoll
()
:
undefined
,
...
...
@@ -272,7 +288,7 @@ export class NoteRepository extends Repository<Note> {
return
packed
;
}
public
packMany
(
public
async
packMany
(
notes
:
(
Note
[
'
id
'
]
|
Note
)[],
me
?:
User
[
'
id
'
]
|
User
|
null
|
undefined
,
options
?:
{
...
...
@@ -280,7 +296,30 @@ export class NoteRepository extends Repository<Note> {
skipHide
?:
boolean
;
}
)
{
return
Promise
.
all
(
notes
.
map
(
n
=>
this
.
pack
(
n
,
me
,
options
)));
if
(
notes
.
length
===
0
)
return
[];
const
meId
=
me
?
typeof
me
===
'
string
'
?
me
:
me
.
id
:
null
;
const
noteIds
=
notes
.
map
(
n
=>
typeof
n
===
'
object
'
?
n
.
id
:
n
);
const
myReactionsMap
=
new
Map
<
Note
[
'
id
'
],
NoteReaction
|
null
>
();
if
(
meId
)
{
const
renoteIds
=
notes
.
filter
(
n
=>
(
typeof
n
===
'
object
'
)
&&
(
n
.
renoteId
!=
null
)).
map
(
n
=>
(
n
as
Note
).
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
(
notes
.
map
(
n
=>
this
.
pack
(
n
,
me
,
{
...
options
,
_hint_
:
{
myReactions
:
myReactionsMap
}
})));
}
}
...
...
This diff is collapsed.
Click to expand it.
src/services/note/reaction/create.ts
+
1
−
0
View file @
65e7204e
...
...
@@ -15,6 +15,7 @@ import { isDuplicateKeyValueError } from '../../../misc/is-duplicate-key-value-e
import
{
NoteReaction
}
from
'
../../../models/entities/note-reaction
'
;
export
default
async
(
user
:
User
,
note
:
Note
,
reaction
?:
string
)
=>
{
// TODO: cache
reaction
=
await
toDbReaction
(
reaction
,
user
.
host
);
let
record
:
NoteReaction
;
...
...
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