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
fa67fb42
Commit
fa67fb42
authored
1 year ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
enhance(backend): Redisにチャンネル投稿がない場合はDBから持ってくるように
Fix #10473
parent
40b30416
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
packages/backend/src/server/api/endpoints/channels/timeline.ts
+47
-28
47 additions, 28 deletions
...ges/backend/src/server/api/endpoints/channels/timeline.ts
with
47 additions
and
28 deletions
packages/backend/src/server/api/endpoints/channels/timeline.ts
+
47
−
28
View file @
fa67fb42
import
{
Inject
,
Injectable
}
from
'
@nestjs/common
'
;
import
Redis
from
'
ioredis
'
;
import
{
Endpoint
}
from
'
@/server/api/endpoint-base.js
'
;
import
type
{
ChannelsRepository
,
NotesRepository
}
from
'
@/models/index.js
'
;
import
type
{
ChannelsRepository
,
Note
,
NotesRepository
}
from
'
@/models/index.js
'
;
import
{
QueryService
}
from
'
@/core/QueryService.js
'
;
import
{
NoteEntityService
}
from
'
@/core/entities/NoteEntityService.js
'
;
import
ActiveUsersChart
from
'
@/core/chart/charts/active-users.js
'
;
...
...
@@ -73,6 +73,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
throw
new
ApiError
(
meta
.
errors
.
noSuchChannel
);
}
let
timeline
:
Note
[]
=
[];
const
noteIdsRes
=
await
this
.
redisClient
.
xrevrange
(
`channelTimeline:
${
channel
.
id
}
`
,
ps
.
untilId
?
this
.
idService
.
parse
(
ps
.
untilId
).
date
.
getTime
()
:
'
+
'
,
...
...
@@ -80,35 +82,52 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
'
COUNT
'
,
ps
.
limit
+
1
);
// untilIdに指定したものも含まれるため+1
if
(
noteIdsRes
.
length
===
0
)
{
return
[];
}
const
noteIds
=
noteIdsRes
.
map
(
x
=>
x
[
1
][
1
]).
filter
(
x
=>
x
!==
ps
.
untilId
);
if
(
noteIds
.
length
===
0
)
{
return
[];
//#region Construct query
const
query
=
this
.
queryService
.
makePaginationQuery
(
this
.
notesRepository
.
createQueryBuilder
(
'
note
'
),
ps
.
sinceId
,
ps
.
untilId
,
ps
.
sinceDate
,
ps
.
untilDate
)
.
andWhere
(
'
note.channelId = :channelId
'
,
{
channelId
:
channel
.
id
})
.
innerJoinAndSelect
(
'
note.user
'
,
'
user
'
)
.
leftJoinAndSelect
(
'
note.reply
'
,
'
reply
'
)
.
leftJoinAndSelect
(
'
note.renote
'
,
'
renote
'
)
.
leftJoinAndSelect
(
'
reply.user
'
,
'
replyUser
'
)
.
leftJoinAndSelect
(
'
renote.user
'
,
'
renoteUser
'
)
.
leftJoinAndSelect
(
'
note.channel
'
,
'
channel
'
);
if
(
me
)
{
this
.
queryService
.
generateMutedUserQuery
(
query
,
me
);
this
.
queryService
.
generateMutedNoteQuery
(
query
,
me
);
this
.
queryService
.
generateBlockedUserQuery
(
query
,
me
);
}
//#endregion
timeline
=
await
query
.
take
(
ps
.
limit
).
getMany
();
}
else
{
const
noteIds
=
noteIdsRes
.
map
(
x
=>
x
[
1
][
1
]).
filter
(
x
=>
x
!==
ps
.
untilId
);
if
(
noteIds
.
length
===
0
)
{
return
[];
}
//#region Construct query
const
query
=
this
.
notesRepository
.
createQueryBuilder
(
'
note
'
)
.
where
(
'
note.id IN (:...noteIds)
'
,
{
noteIds
:
noteIds
})
.
innerJoinAndSelect
(
'
note.user
'
,
'
user
'
)
.
leftJoinAndSelect
(
'
note.reply
'
,
'
reply
'
)
.
leftJoinAndSelect
(
'
note.renote
'
,
'
renote
'
)
.
leftJoinAndSelect
(
'
reply.user
'
,
'
replyUser
'
)
.
leftJoinAndSelect
(
'
renote.user
'
,
'
renoteUser
'
)
.
leftJoinAndSelect
(
'
note.channel
'
,
'
channel
'
);
if
(
me
)
{
this
.
queryService
.
generateMutedUserQuery
(
query
,
me
);
this
.
queryService
.
generateMutedNoteQuery
(
query
,
me
);
this
.
queryService
.
generateBlockedUserQuery
(
query
,
me
);
}
//#endregion
timeline
=
await
query
.
getMany
();
timeline
.
sort
((
a
,
b
)
=>
a
.
id
>
b
.
id
?
-
1
:
1
);
}
//#region Construct query
const
query
=
this
.
notesRepository
.
createQueryBuilder
(
'
note
'
)
.
where
(
'
note.id IN (:...noteIds)
'
,
{
noteIds
:
noteIds
})
.
innerJoinAndSelect
(
'
note.user
'
,
'
user
'
)
.
leftJoinAndSelect
(
'
note.reply
'
,
'
reply
'
)
.
leftJoinAndSelect
(
'
note.renote
'
,
'
renote
'
)
.
leftJoinAndSelect
(
'
reply.user
'
,
'
replyUser
'
)
.
leftJoinAndSelect
(
'
renote.user
'
,
'
renoteUser
'
)
.
leftJoinAndSelect
(
'
note.channel
'
,
'
channel
'
);
if
(
me
)
{
this
.
queryService
.
generateMutedUserQuery
(
query
,
me
);
this
.
queryService
.
generateMutedNoteQuery
(
query
,
me
);
this
.
queryService
.
generateBlockedUserQuery
(
query
,
me
);
}
//#endregion
const
timeline
=
await
query
.
getMany
();
timeline
.
sort
((
a
,
b
)
=>
a
.
id
>
b
.
id
?
-
1
:
1
);
if
(
me
)
this
.
activeUsersChart
.
read
(
me
);
return
await
this
.
noteEntityService
.
packMany
(
timeline
,
me
);
...
...
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