Skip to content

Reset project counters after relation import

James Nutt requested to merge jnutt/461812-reset-project-counters into master

What does this MR do and why?

Reset project counters after relation import

Relation import doesn't currently run the post-import hooks. Most of these aren't relevant to partial imports, but we need to recalculate the project counters to correctly calculate IIDs and display relation counts in the navigation.

Changelog: fixed

Related issue: #461812 (closed)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Take note of the project and merge request count in the sidebar.
  2. Export a project via project settings.
  3. Delete an issue and a merge request.
    p = Project.find(PROJECT_ID_HERE)
    p.issues.last.destroy
    p.merge_requests.last.destroy
  4. Recalculate project stats.
    p.reset_counters_and_iids
  5. Take note of the project and merge request count in the sidebar. They should each have decreased by 1.
  6. Re-import the project.
    curl --request POST --header "PRIVATE-TOKEN: $GITLAB_DEV_TOKEN" \
      --form "path=project/path" \
      --form "relation=issues" \
      --form "file=@export.tar.gz" \
      "http://gdk.test:3000/api/v4/projects/import-relation"
    curl --request POST --header "PRIVATE-TOKEN: $GITLAB_DEV_TOKEN" \
      --form "path=project/path" \
      --form "relation=merge_requests" \
      --form "file=@export.tar.gz" \
      "http://gdk.test:3000/api/v4/projects/import-relation"
  7. Confirm that the issue and MR counts have been correctly reset.
Edited by James Nutt

Merge request reports