Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
694a7df9
Commit
694a7df9
authored
Jul 23, 2018
by
Tim Zallmann
Committed by
Fatih Acet
Jul 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving performance of posting a comment by reducing memory + CPU
parent
c1b335e0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
26 deletions
+13
-26
app/assets/javascripts/lib/utils/poll.js
app/assets/javascripts/lib/utils/poll.js
+6
-5
app/assets/javascripts/notes/stores/mutations.js
app/assets/javascripts/notes/stores/mutations.js
+4
-15
app/assets/javascripts/notes/stores/utils.js
app/assets/javascripts/notes/stores/utils.js
+3
-6
No files found.
app/assets/javascripts/lib/utils/poll.js
View file @
694a7df9
...
@@ -38,7 +38,7 @@ import { normalizeHeaders } from './common_utils';
...
@@ -38,7 +38,7 @@ import { normalizeHeaders } from './common_utils';
* } else {
* } else {
* poll.stop();
* poll.stop();
* }
* }
* });
* });
*
*
* 1. Checks for response and headers before start polling
* 1. Checks for response and headers before start polling
* 2. Interval is provided by `Poll-Interval` header.
* 2. Interval is provided by `Poll-Interval` header.
...
@@ -51,8 +51,8 @@ export default class Poll {
...
@@ -51,8 +51,8 @@ export default class Poll {
constructor
(
options
=
{})
{
constructor
(
options
=
{})
{
this
.
options
=
options
;
this
.
options
=
options
;
this
.
options
.
data
=
options
.
data
||
{};
this
.
options
.
data
=
options
.
data
||
{};
this
.
options
.
notificationCallback
=
options
.
notificationCallback
||
this
.
options
.
notificationCallback
=
function
notificationCallback
()
{};
options
.
notificationCallback
||
function
notificationCallback
()
{};
this
.
intervalHeader
=
'
POLL-INTERVAL
'
;
this
.
intervalHeader
=
'
POLL-INTERVAL
'
;
this
.
timeoutID
=
null
;
this
.
timeoutID
=
null
;
...
@@ -63,6 +63,7 @@ export default class Poll {
...
@@ -63,6 +63,7 @@ export default class Poll {
const
headers
=
normalizeHeaders
(
response
.
headers
);
const
headers
=
normalizeHeaders
(
response
.
headers
);
const
pollInterval
=
parseInt
(
headers
[
this
.
intervalHeader
],
10
);
const
pollInterval
=
parseInt
(
headers
[
this
.
intervalHeader
],
10
);
if
(
pollInterval
>
0
&&
response
.
status
===
httpStatusCodes
.
OK
&&
this
.
canPoll
)
{
if
(
pollInterval
>
0
&&
response
.
status
===
httpStatusCodes
.
OK
&&
this
.
canPoll
)
{
clearTimeout
(
this
.
timeoutID
);
this
.
timeoutID
=
setTimeout
(()
=>
{
this
.
timeoutID
=
setTimeout
(()
=>
{
this
.
makeRequest
();
this
.
makeRequest
();
},
pollInterval
);
},
pollInterval
);
...
@@ -77,11 +78,11 @@ export default class Poll {
...
@@ -77,11 +78,11 @@ export default class Poll {
notificationCallback
(
true
);
notificationCallback
(
true
);
return
resource
[
method
](
data
)
return
resource
[
method
](
data
)
.
then
(
(
response
)
=>
{
.
then
(
response
=>
{
this
.
checkConditions
(
response
);
this
.
checkConditions
(
response
);
notificationCallback
(
false
);
notificationCallback
(
false
);
})
})
.
catch
(
(
error
)
=>
{
.
catch
(
error
=>
{
notificationCallback
(
false
);
notificationCallback
(
false
);
if
(
error
.
status
===
httpStatusCodes
.
ABORTED
)
{
if
(
error
.
status
===
httpStatusCodes
.
ABORTED
)
{
return
;
return
;
...
...
app/assets/javascripts/notes/stores/mutations.js
View file @
694a7df9
...
@@ -174,27 +174,19 @@ export default {
...
@@ -174,27 +174,19 @@ export default {
[
types
.
UPDATE_NOTE
](
state
,
note
)
{
[
types
.
UPDATE_NOTE
](
state
,
note
)
{
const
noteObj
=
utils
.
findNoteObjectById
(
state
.
discussions
,
note
.
discussion_id
);
const
noteObj
=
utils
.
findNoteObjectById
(
state
.
discussions
,
note
.
discussion_id
);
if
(
noteObj
.
individual_note
)
{
if
(
noteObj
.
individual_note
)
{
noteObj
.
notes
.
splice
(
0
,
1
,
note
);
noteObj
.
notes
.
splice
(
0
,
1
,
note
);
}
else
{
}
else
{
const
comment
=
utils
.
findNoteObjectById
(
noteObj
.
notes
,
note
.
id
);
const
comment
=
utils
.
findNoteObjectById
(
noteObj
.
notes
,
note
.
id
);
noteObj
.
notes
.
splice
(
noteObj
.
notes
.
indexOf
(
comment
),
1
,
note
);
Object
.
assign
(
comment
,
note
);
}
}
},
},
[
types
.
UPDATE_DISCUSSION
](
state
,
noteData
)
{
[
types
.
UPDATE_DISCUSSION
](
state
,
noteData
)
{
const
note
=
noteData
;
const
note
=
noteData
;
let
index
=
0
;
const
selectedDiscussion
=
state
.
discussions
.
find
(
n
=>
n
.
id
===
note
.
id
);
state
.
discussions
.
forEach
((
n
,
i
)
=>
{
if
(
n
.
id
===
note
.
id
)
{
index
=
i
;
}
});
note
.
expanded
=
true
;
// override expand flag to prevent collapse
note
.
expanded
=
true
;
// override expand flag to prevent collapse
state
.
discussions
.
splice
(
index
,
1
,
note
);
Object
.
assign
(
selectedDiscussion
,
note
);
},
},
[
types
.
CLOSE_ISSUE
](
state
)
{
[
types
.
CLOSE_ISSUE
](
state
)
{
...
@@ -215,12 +207,9 @@ export default {
...
@@ -215,12 +207,9 @@ export default {
[
types
.
SET_DISCUSSION_DIFF_LINES
](
state
,
{
discussionId
,
diffLines
})
{
[
types
.
SET_DISCUSSION_DIFF_LINES
](
state
,
{
discussionId
,
diffLines
})
{
const
discussion
=
utils
.
findNoteObjectById
(
state
.
discussions
,
discussionId
);
const
discussion
=
utils
.
findNoteObjectById
(
state
.
discussions
,
discussionId
);
const
index
=
state
.
discussions
.
indexOf
(
discussion
);
const
discussionWithDiffLines
=
Object
.
assign
({},
discussion
,
{
Object
.
assign
(
discussion
,
{
truncated_diff_lines
:
diffLines
,
truncated_diff_lines
:
diffLines
,
});
});
state
.
discussions
.
splice
(
index
,
1
,
discussionWithDiffLines
);
},
},
};
};
app/assets/javascripts/notes/stores/utils.js
View file @
694a7df9
...
@@ -2,13 +2,11 @@ import AjaxCache from '~/lib/utils/ajax_cache';
...
@@ -2,13 +2,11 @@ import AjaxCache from '~/lib/utils/ajax_cache';
const
REGEX_QUICK_ACTIONS
=
/^
\/\w
+.*$/gm
;
const
REGEX_QUICK_ACTIONS
=
/^
\/\w
+.*$/gm
;
export
const
findNoteObjectById
=
(
notes
,
id
)
=>
export
const
findNoteObjectById
=
(
notes
,
id
)
=>
notes
.
find
(
n
=>
n
.
id
===
id
);
notes
.
filter
(
n
=>
n
.
id
===
id
)[
0
];
export
const
getQuickActionText
=
note
=>
{
export
const
getQuickActionText
=
note
=>
{
let
text
=
'
Applying command
'
;
let
text
=
'
Applying command
'
;
const
quickActions
=
const
quickActions
=
AjaxCache
.
get
(
gl
.
GfmAutoComplete
.
dataSources
.
commands
)
||
[];
AjaxCache
.
get
(
gl
.
GfmAutoComplete
.
dataSources
.
commands
)
||
[];
const
executedCommands
=
quickActions
.
filter
(
command
=>
{
const
executedCommands
=
quickActions
.
filter
(
command
=>
{
const
commandRegex
=
new
RegExp
(
`/
${
command
.
name
}
`
);
const
commandRegex
=
new
RegExp
(
`/
${
command
.
name
}
`
);
...
@@ -29,5 +27,4 @@ export const getQuickActionText = note => {
...
@@ -29,5 +27,4 @@ export const getQuickActionText = note => {
export
const
hasQuickActions
=
note
=>
REGEX_QUICK_ACTIONS
.
test
(
note
);
export
const
hasQuickActions
=
note
=>
REGEX_QUICK_ACTIONS
.
test
(
note
);
export
const
stripQuickActions
=
note
=>
export
const
stripQuickActions
=
note
=>
note
.
replace
(
REGEX_QUICK_ACTIONS
,
''
).
trim
();
note
.
replace
(
REGEX_QUICK_ACTIONS
,
''
).
trim
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment