Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
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
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
99924f28
Commit
99924f28
authored
5 years ago
by
ThibG
Committed by
Eugen Rochko
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Memoize ancestorIds and descendantIds in detailed status view (#11234)
parent
3bc0c4a8
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
app/javascript/mastodon/features/status/index.js
+44
-24
44 additions, 24 deletions
app/javascript/mastodon/features/status/index.js
with
44 additions
and
24 deletions
app/javascript/mastodon/features/status/index.js
+
44
−
24
View file @
99924f28
...
...
@@ -4,6 +4,7 @@ import { connect } from 'react-redux';
import
PropTypes
from
'
prop-types
'
;
import
classNames
from
'
classnames
'
;
import
ImmutablePropTypes
from
'
react-immutable-proptypes
'
;
import
{
createSelector
}
from
'
reselect
'
;
import
{
fetchStatus
}
from
'
../../actions/statuses
'
;
import
MissingIndicator
from
'
../../components/missing_indicator
'
;
import
DetailedStatus
from
'
./components/detailed_status
'
;
...
...
@@ -63,39 +64,58 @@ const messages = defineMessages({
const
makeMapStateToProps
=
()
=>
{
const
getStatus
=
makeGetStatus
();
const
mapStateToProps
=
(
state
,
props
)
=>
{
const
status
=
getStatus
(
state
,
{
id
:
props
.
params
.
statusId
});
const
getAncestorsIds
=
createSelector
([
(
_
,
{
id
})
=>
id
,
state
=>
state
.
getIn
([
'
contexts
'
,
'
inReplyTos
'
]),
],
(
statusId
,
inReplyTos
)
=>
{
let
ancestorsIds
=
Immutable
.
List
();
ancestorsIds
=
ancestorsIds
.
withMutations
(
mutable
=>
{
let
id
=
statusId
;
while
(
id
)
{
mutable
.
unshift
(
id
);
id
=
inReplyTos
.
get
(
id
);
}
});
return
ancestorsIds
;
});
const
getDescendantsIds
=
createSelector
([
(
_
,
{
id
})
=>
id
,
state
=>
state
.
getIn
([
'
contexts
'
,
'
replies
'
]),
],
(
statusId
,
contextReplies
)
=>
{
let
descendantsIds
=
Immutable
.
List
();
descendantsIds
=
descendantsIds
.
withMutations
(
mutable
=>
{
const
ids
=
[
statusId
];
if
(
status
)
{
ancestorsIds
=
ancestorsIds
.
withMutations
(
mutable
=>
{
let
id
=
status
.
get
(
'
in_reply_to_
id
'
);
while
(
ids
.
length
>
0
)
{
let
id
=
ids
.
shift
();
const
replies
=
contextReplies
.
get
(
id
);
while
(
id
)
{
mutable
.
unshift
(
id
);
id
=
state
.
getIn
([
'
contexts
'
,
'
inReplyTos
'
,
id
]);
if
(
statusId
!==
id
)
{
mutable
.
push
(
id
);
}
});
descendantsIds
=
descendantsIds
.
withMutations
(
mutable
=>
{
const
ids
=
[
status
.
get
(
'
id
'
)];
if
(
replies
)
{
replies
.
reverse
().
forEach
(
reply
=>
{
ids
.
unshift
(
reply
);
});
}
}
});
while
(
ids
.
length
>
0
)
{
let
id
=
ids
.
shift
();
const
replies
=
state
.
getIn
([
'
contexts
'
,
'
replies
'
,
id
]);
return
descendantsIds
;
});
if
(
status
.
get
(
'
id
'
)
!==
id
)
{
mutable
.
push
(
id
);
}
const
mapStateToProps
=
(
state
,
props
)
=>
{
const
status
=
getStatus
(
state
,
{
id
:
props
.
params
.
statusId
});
let
ancestorsIds
=
Immutable
.
List
();
let
descendantsIds
=
Immutable
.
List
();
if
(
replies
)
{
replies
.
reverse
().
forEach
(
reply
=>
{
ids
.
unshift
(
reply
);
});
}
}
});
if
(
status
)
{
ancestorsIds
=
getAncestorsIds
(
state
,
{
id
:
status
.
get
(
'
in_reply_to_id
'
)
});
descendantsIds
=
getDescendantsIds
(
state
,
{
id
:
status
.
get
(
'
id
'
)
});
}
return
{
...
...
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