Commit Graph

18 Commits

Author SHA1 Message Date
Douwe Maan 338d9b257e Don't return nil for missing objects from parser cache 2017-06-14 13:01:15 -05:00
DJ Mountney ae6adf165c Merge branch '25934-project-snippet-vis' into 'security-9-2'
Fix visibility when referencing snippets

See merge request !2101
2017-06-08 09:56:39 -07:00
Sean McGivern 172932eec8 Fix /unsubscribe slash command creating extra todos
The /unsubscribe slash command means that we check if the current user is
subscribed to the issuable without having an explicit subscription. That means
that we use the UserParser to find references to them in the notes.

The UserParser (and all parsers inheriting from BaseParser) use RequestStore to
cache ActiveRecord objects, so that we don't need to load the User object each
time, if we're parsing references a bunch of times in the same request.

However, it was always returning _all_ of the previously cached items, not just
the ones matching the IDs passed. This would mean that we did two runs through
with UserParser if you were mentioned in a comment, and then mentioned someone
else in your comment while using /unsubscribe:

1. Because /unsubscribe was used, we see if you were mentioned in any comments.
2. Because you mentioned someone, we find them - but we would also get back your
   user, even if you didn't mention yourself. This would have the effect of
   creating a mention or directly addressed todo for yourself incorrectly.

The fix is simple: only return values from the cache matching the IDs passed.
2017-05-30 11:24:55 +01:00
Valery Sizov 387c4b2c21 Backport of multiple_assignees_feature [ci skip] 2017-05-04 17:11:53 +03:00
Sean McGivern 52d049b4f8 Remove N+1 queries when checking nodes visible to user
N in this case is low, as it's the number of distinct projects referenced from
MRs, rather than the number of MRs referenced (issues use their own
optimization). Still, on issues or MRs which are often referenced from MRs, it
will save a few queries.
2017-05-02 17:35:19 +01:00
Stan Hu e89d4741d3 Fix regression in rendering Markdown references that do not exist
Closes #30972
2017-04-15 07:26:32 -07:00
Adam Niedzielski 3fa898549c Reuse "merge_requests_for_nodes" in "MergeRequestParser" 2017-04-10 12:42:20 +02:00
Adam Buckland ace833b31d Add indication for closed or merged issuables in GFM
Example: for issues that are closed, the links will now show '[closed]'
following the issue number. This is done as post-process after the markdown has
been loaded from the cache as the status of the issue may change between
the cache being populated and the content being displayed.

In order to avoid N+1 queries problem when rendering notes ObjectRenderer
populates the cache of referenced issuables for all notes at once,
before the post processing phase.

As a part of this change, the Banzai BaseParser#grouped_objects_for_nodes
method has been refactored to return a Hash utilising the node itself as the
key, since this was a common pattern of usage for this method.
2017-04-07 14:31:43 -05:00
Douwe Maan 871bed7ac0 Use Enumerable#index_by where possible 2017-03-16 16:33:15 -06:00
http://jneen.net/ 846e581732 use a magic default :global symbol instead of nil
to make sure we mean the global permissions
2017-03-09 11:49:52 -08:00
Ershad Kunnakkadan 3a23639bc0
Create directly_addressed Todos when mentioned in beginning of a line 2017-02-08 21:53:34 +05:30
Douwe Maan bf061d0aff
Merge branch 'issue_23548_dev' into 'master'
disable markdown in comments when referencing disabled features

fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/23548

This MR prevents the following references when tool is disabled:

- issues
- snippets
- commits - when repo is disabled
- commit range - when repo is disabled
- milestones

This MR does not prevent references to repository files, since they are just markdown links and don't leak
information.

See merge request !2011

Signed-off-by: Rémy Coutable <remy@rymai.me>
2016-11-09 12:25:17 +01:00
Paco Guzman f4a84f504f Avoid database queries on Banzai::ReferenceParser::BaseParser for nodes without references 2016-09-28 09:08:28 +02:00
http://jneen.net/ 5853c96b49 remove Ability.abilities 2016-08-30 11:35:06 -07:00
Yorick Peterse 002ad21581
Method for returning issues readable by a user
The method Ability.issues_readable_by_user takes a list of users and an
optional user and returns an Array of issues readable by said user. This
method in turn is used by
Banzai::ReferenceParser::IssueParser#nodes_visible_to_user so this
method no longer needs to get all the available abilities just to check
if a user has the "read_issue" ability.

To test this I benchmarked an issue with 222 comments on my development
environment. Using these changes the time spent in nodes_visible_to_user
was reduced from around 120 ms to around 40 ms.
2016-07-29 12:51:18 +02:00
Yorick Peterse 9ac4c556ea
Re-use queries in reference parsers
This caches various queries to ensure that multiple reference extraction
runs re-use any objects queried in previous runs.
2016-07-08 21:54:35 +02:00
Yorick Peterse fce675d7fc
Eager load project relations in IssueParser
By eager loading these associations we can greatly cut down the number
of SQL queries executed when processing documents with lots of
references, especially in cases where there are references belonging to
the same project.

Since these associations are so specific to the reference parsing
process and the permissions checking process that follows it I opted to
include them directly in IssueParser instead of using something like a
scope. Once we have a need for it we can move this code to a scope or
method.
2016-06-15 15:30:34 +02:00
Yorick Peterse 86166d2802
Split Markdown rendering & reference gathering
This splits the Markdown rendering and reference extraction phases into
two distinct code bases. The reference extraction phase no longer relies
on the html-pipeline Gem (and any related code) and allows for
extracting of references from multiple HTML nodes in a single pass. This
means that if you want to extract user references from 200 comments you
no longer need to run 200 times N number of queries, instead only a
handful of queries may be needed.
2016-05-26 17:14:00 +02:00