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
6b5ee438
Commit
6b5ee438
authored
1 year ago
by
syuilo
Browse files
Options
Downloads
Patches
Plain Diff
enhance(backend): improve fanout tl for stl
parent
6b7efb6f
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/notes/hybrid-timeline.ts
+103
-35
103 additions, 35 deletions
...backend/src/server/api/endpoints/notes/hybrid-timeline.ts
with
103 additions
and
35 deletions
packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
+
103
−
35
View file @
6b5ee438
...
...
@@ -5,7 +5,6 @@
import
{
Brackets
}
from
'
typeorm
'
;
import
{
Inject
,
Injectable
}
from
'
@nestjs/common
'
;
import
*
as
Redis
from
'
ioredis
'
;
import
type
{
NotesRepository
,
FollowingsRepository
,
MiNote
}
from
'
@/models/_.js
'
;
import
{
Endpoint
}
from
'
@/server/api/endpoint-base.js
'
;
import
ActiveUsersChart
from
'
@/core/chart/charts/active-users.js
'
;
...
...
@@ -16,6 +15,8 @@ import { IdService } from '@/core/IdService.js';
import
{
isUserRelated
}
from
'
@/misc/is-user-related.js
'
;
import
{
CacheService
}
from
'
@/core/CacheService.js
'
;
import
{
FunoutTimelineService
}
from
'
@/core/FunoutTimelineService.js
'
;
import
{
QueryService
}
from
'
@/core/QueryService.js
'
;
import
{
UserFollowingService
}
from
'
@/core/UserFollowingService.js
'
;
import
{
ApiError
}
from
'
../../error.js
'
;
export
const
meta
=
{
...
...
@@ -63,9 +64,6 @@ export const paramDef = {
@
Injectable
()
export
default
class
extends
Endpoint
<
typeof
meta
,
typeof
paramDef
>
{
// eslint-disable-line import/no-default-export
constructor
(
@
Inject
(
DI
.
redisForTimelines
)
private
redisForTimelines
:
Redis
.
Redis
,
@
Inject
(
DI
.
notesRepository
)
private
notesRepository
:
NotesRepository
,
...
...
@@ -75,6 +73,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private
idService
:
IdService
,
private
cacheService
:
CacheService
,
private
funoutTimelineService
:
FunoutTimelineService
,
private
queryService
:
QueryService
,
private
userFollowingService
:
UserFollowingService
,
)
{
super
(
meta
,
paramDef
,
async
(
ps
,
me
)
=>
{
const
untilId
=
ps
.
untilId
??
(
ps
.
untilDate
?
this
.
idService
.
gen
(
ps
.
untilDate
!
)
:
null
);
...
...
@@ -96,6 +96,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
]);
let
noteIds
:
string
[];
let
shouldFallbackToDb
=
false
;
if
(
ps
.
withFiles
)
{
const
[
htlNoteIds
,
ltlNoteIds
]
=
await
this
.
funoutTimelineService
.
getMulti
([
...
...
@@ -116,51 +117,118 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
'
localTimeline
'
,
],
untilId
,
sinceId
);
noteIds
=
Array
.
from
(
new
Set
([...
htlNoteIds
,
...
ltlNoteIds
]));
shouldFallbackToDb
=
htlNoteIds
.
length
===
0
;
}
noteIds
.
sort
((
a
,
b
)
=>
a
>
b
?
-
1
:
1
);
noteIds
=
noteIds
.
slice
(
0
,
ps
.
limit
);
if
(
noteIds
.
length
===
0
)
{
return
[];
}
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
'
);
let
timeline
=
await
query
.
getMany
();
if
(
!
shouldFallbackToDb
)
{
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
'
);
let
timeline
=
await
query
.
getMany
();
timeline
=
timeline
.
filter
(
note
=>
{
if
(
note
.
userId
===
me
.
id
)
{
return
true
;
}
if
(
isUserRelated
(
note
,
userIdsWhoBlockingMe
))
return
false
;
if
(
isUserRelated
(
note
,
userIdsWhoMeMuting
))
return
false
;
if
(
note
.
renoteId
)
{
if
(
note
.
text
==
null
&&
note
.
fileIds
.
length
===
0
&&
!
note
.
hasPoll
)
{
if
(
isUserRelated
(
note
,
userIdsWhoMeMutingRenotes
))
return
false
;
if
(
ps
.
withRenotes
===
false
)
return
false
;
}
}
timeline
=
timeline
.
filter
(
note
=>
{
if
(
note
.
userId
===
me
.
id
)
{
return
true
;
});
// TODO: フィルタした結果件数が足りなかった場合の対応
timeline
.
sort
((
a
,
b
)
=>
a
.
id
>
b
.
id
?
-
1
:
1
);
process
.
nextTick
(()
=>
{
this
.
activeUsersChart
.
read
(
me
);
});
return
await
this
.
noteEntityService
.
packMany
(
timeline
,
me
);
}
else
{
// fallback to db
const
followees
=
await
this
.
userFollowingService
.
getFollowees
(
me
.
id
);
const
query
=
this
.
queryService
.
makePaginationQuery
(
this
.
notesRepository
.
createQueryBuilder
(
'
note
'
),
ps
.
sinceId
,
ps
.
untilId
,
ps
.
sinceDate
,
ps
.
untilDate
)
.
andWhere
(
new
Brackets
(
qb
=>
{
if
(
followees
.
length
>
0
)
{
const
meOrFolloweeIds
=
[
me
.
id
,
...
followees
.
map
(
f
=>
f
.
followeeId
)];
qb
.
where
(
'
note.userId IN (:...meOrFolloweeIds)
'
,
{
meOrFolloweeIds
:
meOrFolloweeIds
});
qb
.
orWhere
(
'
(note.visibility =
\'
public
\'
) AND (note.userHost IS NULL)
'
);
}
else
{
qb
.
where
(
'
note.userId = :meId
'
,
{
meId
:
me
.
id
});
qb
.
orWhere
(
'
(note.visibility =
\'
public
\'
) AND (note.userHost IS NULL)
'
);
}
}))
.
innerJoinAndSelect
(
'
note.user
'
,
'
user
'
)
.
leftJoinAndSelect
(
'
note.reply
'
,
'
reply
'
)
.
leftJoinAndSelect
(
'
note.renote
'
,
'
renote
'
)
.
leftJoinAndSelect
(
'
reply.user
'
,
'
replyUser
'
)
.
leftJoinAndSelect
(
'
renote.user
'
,
'
renoteUser
'
);
this
.
queryService
.
generateVisibilityQuery
(
query
,
me
);
this
.
queryService
.
generateMutedUserQuery
(
query
,
me
);
this
.
queryService
.
generateBlockedUserQuery
(
query
,
me
);
this
.
queryService
.
generateMutedUserRenotesQueryForNotes
(
query
,
me
);
if
(
ps
.
includeMyRenotes
===
false
)
{
query
.
andWhere
(
new
Brackets
(
qb
=>
{
qb
.
orWhere
(
'
note.userId != :meId
'
,
{
meId
:
me
.
id
});
qb
.
orWhere
(
'
note.renoteId IS NULL
'
);
qb
.
orWhere
(
'
note.text IS NOT NULL
'
);
qb
.
orWhere
(
'
note.fileIds !=
\'
{}
\'
'
);
qb
.
orWhere
(
'
0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)
'
);
}));
}
if
(
isUserRelated
(
note
,
userIdsWhoBlockingMe
))
return
false
;
if
(
isUserRelated
(
note
,
userIdsWhoMeMuting
))
return
false
;
if
(
note
.
renoteId
)
{
if
(
note
.
text
==
null
&&
note
.
fileIds
.
length
===
0
&&
!
note
.
hasPoll
)
{
if
(
isUserRelated
(
note
,
userIdsWhoMeMutingRenotes
))
return
false
;
if
(
ps
.
withRenotes
===
false
)
return
false
;
}
if
(
ps
.
includeRenotedMyNotes
===
false
)
{
query
.
andWhere
(
new
Brackets
(
qb
=>
{
qb
.
orWhere
(
'
note.renoteUserId != :meId
'
,
{
meId
:
me
.
id
});
qb
.
orWhere
(
'
note.renoteId IS NULL
'
);
qb
.
orWhere
(
'
note.text IS NOT NULL
'
);
qb
.
orWhere
(
'
note.fileIds !=
\'
{}
\'
'
);
qb
.
orWhere
(
'
0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)
'
);
}));
}
return
true
;
});
if
(
ps
.
includeLocalRenotes
===
false
)
{
query
.
andWhere
(
new
Brackets
(
qb
=>
{
qb
.
orWhere
(
'
note.renoteUserHost IS NOT NULL
'
);
qb
.
orWhere
(
'
note.renoteId IS NULL
'
);
qb
.
orWhere
(
'
note.text IS NOT NULL
'
);
qb
.
orWhere
(
'
note.fileIds !=
\'
{}
\'
'
);
qb
.
orWhere
(
'
0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)
'
);
}));
}
// TODO: フィルタした結果件数が足りなかった場合の対応
if
(
ps
.
withFiles
)
{
query
.
andWhere
(
'
note.fileIds !=
\'
{}
\'
'
);
}
//#endregion
timeline
.
sort
((
a
,
b
)
=
>
a
.
id
>
b
.
id
?
-
1
:
1
);
const
timeline
=
a
wait
query
.
limit
(
ps
.
limit
).
getMany
(
);
process
.
nextTick
(()
=>
{
this
.
activeUsersChart
.
read
(
me
);
});
process
.
nextTick
(()
=>
{
this
.
activeUsersChart
.
read
(
me
);
});
return
await
this
.
noteEntityService
.
packMany
(
timeline
,
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