Skip to content
Snippets Groups Projects
  1. Sep 04, 2019
  2. Oct 08, 2018
    • Yorick Peterse's avatar
      Clean up ActiveRecord code in TodoService · 38b8ae64
      Yorick Peterse authored
      This refactors the TodoService class according to our code reuse
      guidelines. The resulting code is a wee bit more verbose, but it allows
      us to decouple the column names from the input, resulting in fewer
      changes being necessary when we change the schema.
      
      One particular noteworthy line in TodoService is the following:
      
          todos_ids = todos.update_state(state)
      
      Technically this is a violation of the guidelines, because
      `update_state` is a class method, which services are not supposed to use
      (safe for a few allowed ones). I decided to keep this, since there is no
      alternative. `update_state` doesn't produce a relation so it doesn't
      belong in a Finder, and we can't move it to another Service either. As
      such I opted to just use the method directly.
      
      Cases like this may happen more frequently, at which point we should
      update our documentation with some sort of recommendation. For now, I
      want to refrain from doing so until we have a few more examples.
      Unverified
      38b8ae64
    • Yorick Peterse's avatar
      Clean up ActiveRecord code in TodosFinder · 4c1dc310
      Yorick Peterse authored
      This refactors the TodosFinder finder according to the new code reuse
      rules, as enforced by the CodeReuse cops. I also changed some of the
      methods to use regular if statements, instead of assignments and/or
      early returns. This results in a more natural flow when reading the
      code, and it makes it harder to accidentally return the wrong result.
      Unverified
      4c1dc310
  3. Sep 17, 2018
    • Yorick Peterse's avatar
      Added FromUnion to easily select from a UNION · 8a72f5c4
      Yorick Peterse authored
      This commit adds the module `FromUnion`, which provides the class method
      `from_union`. This simplifies the process of selecting data from the
      result of a UNION, and reduces the likelihood of making mistakes. As a
      result, instead of this:
      
          union = Gitlab::SQL::Union.new([foo, bar])
      
          Foo.from("(#{union.to_sql}) #{Foo.table_name}")
      
      We can now write this instead:
      
          Foo.from_union([foo, bar])
      
      This commit also includes some changes to make this new setup work
      properly. For example, a bug in Rails 4
      (https://github.com/rails/rails/issues/24193) would break the use of
      `from("sub-query-here").includes(:relation)` in certain cases. There was
      also a CI query which appeared to repeat a lot of conditions from an
      outer query on an inner query, which isn't necessary.
      
      Finally, we include a RuboCop cop to ensure developers use this new
      module, instead of using Gitlab::SQL::Union directly.
      
      Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/51307
      Verified
      8a72f5c4
  4. Sep 11, 2018
  5. Aug 06, 2018
  6. Aug 02, 2018
  7. Jul 11, 2018
  8. Jul 03, 2018
  9. Apr 04, 2018
  10. Mar 05, 2018
  11. Mar 02, 2018
  12. Feb 22, 2018
  13. Sep 07, 2017
  14. Aug 03, 2017
    • Toon Claes's avatar
      Add workaround for UPDATE with subquery when using MySQL · a488fc0a
      Toon Claes authored
      When trying to run an UPDATE, this query is ran:
      
      ```sql
      UPDATE `todos`
      INNER JOIN `projects` ON `projects`.`id` = `todos`.`project_id`
      SET `todos`.`state` = 'done'
      WHERE `todos`.`user_id` = 4
        AND (`todos`.`state` IN ('pending'))
        AND (EXISTS
               (SELECT 1
                FROM `project_authorizations`
                WHERE `project_authorizations`.`user_id` = 4
                  AND (project_authorizations.project_id = projects.id))
             OR projects.visibility_level IN (10,
                                              20))
        AND `projects`.`id` IN
          (SELECT `todos`.`project_id`
           FROM `todos`
           WHERE `todos`.`user_id` = 4
             AND (`todos`.`state` IN ('pending')))
        AND (`todos`.`state` != 'done')
      ```
      
      But MySQL does not like the subquery used to filter on
      `projects.id IN (SELECT ...`
      
      Because the subquery queries from the same table:
      
      > Error: You can’t specify target table ‘todos’ for update in FROM clause
      
      So as workaround, wrap it in another subquery, where the original
      subquery is aliased using the `AS` statement.
      
      Mostly inspired by https://stackoverflow.com/a/43610081/89376
      a488fc0a
  15. Jun 28, 2017
  16. Jun 02, 2017
  17. Apr 06, 2017
    • Jacopo's avatar
      ProjectsFinder should handle more options · b996a82f
      Jacopo authored
      Extended ProjectFinder in order to handle the following options:
       - current_user - which user use
       - project_ids_relation: int[] - project ids to use
       - params:
         -  trending: boolean
         -  non_public: boolean
         -  starred: boolean
         -  sort: string
         -  visibility_level: int
         -  tags: string[]
         -  personal: boolean
         -  search: string
         -  non_archived: boolean
      
      GroupProjectsFinder now inherits from ProjectsFinder.
      Changed the code in order to use the new available options.
      b996a82f
  18. Mar 21, 2017
  19. Mar 20, 2017
  20. Feb 23, 2017
  21. Aug 30, 2016
  22. Aug 19, 2016
  23. Aug 15, 2016
  24. Aug 12, 2016
    • Rémy Coutable's avatar
      Support slash commands in noteable description and notes · 0eea8c88
      Rémy Coutable authored
      
      Some important things to note:
      
      - commands are removed from noteable.description / note.note
      - commands are translated to params so that they are treated as normal
        params in noteable Creation services
      - the logic is not in the models but in the Creation services, which is
        the right place for advanced logic that has nothing to do with what
        models should be responsible of!
      - UI/JS needs to be updated to handle notes which consist of commands
        only
      - the `/merge` command is not handled yet
      
      Other improvements:
      
      - Don't process commands in commit notes and display a flash is note is only commands
      - Add autocomplete for slash commands
      - Add description and params to slash command DSL methods
      - Ensure replying by email with a commands-only note works
      - Use :subscription_event instead of calling noteable.subscribe
      - Support :todo_event in IssuableBaseService
      
      Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
      0eea8c88
  25. Jul 12, 2016
  26. Jul 01, 2016
  27. Jun 17, 2016
  28. Jun 16, 2016
  29. Jun 14, 2016
  30. Jun 03, 2016
Loading