Skip to content

Use metadata files as the authority for most non-diff file operations

Thomas Randolph requested to merge tor/feature/file-by-file-meta-files into master

What does this MR do and why?

This MR adds a new light-weight array of diff file metadata to the Vuex store, and populates it with the truncated diffs_metadata response when that initially loads from the API.

Why

Context

For #337263 (closed).

We are making File-by-file view mode much more useful by only fetching the single file that you are trying to view at any time.

In extreme cases, if the file you are viewing is the last in a long list (say 100s or 1000s of files), batch-loading the diffs could introduce an extremely noticeable delay before your single file is loaded and displays while the app loads tons of files you have no interest in.

The above issue - and this chain of MRs - will resolve that problem by loading only the file needed to display.

Specifics

Much of the Diffs UI operates based on the length and content of the diffFiles value in the Vuex store.

To be reductive: when it is empty, nothing is shown, and when it has something in it, everything else uses this value for all computations.

As we are now loading a single file at a time, many operations won't work properly unless we switch the source of truth.
A non-exhaustive list of examples is:

  1. Showing the count of total files (it uses the length of diffFiles, but we'll be loading those 1 at a time, so the real number may be different!)
  2. Finding a file's position in the list by path/hash (if the file isn't loaded, it will simply appear to not exist)

To resolve this, this MR is now storing a light-weight version of the diff files when the metadata loads. The light-weight diff file contains necessary information like hash and path, and is also in the appropriate list order, but it doesn't contain information like the actual diff lines themselves.
This MR updates the app to use this light-weight version whenever these other pieces of information are needed ("are there any files?", "what is the next file?", "which file index is foo/path.sh?", etc.) so that they will continue to work even with an incomplete set of fully-loaded diff files.

Roadmap

This MR is one of a set of changes that will eventually implement this feature.

Status MR Purpose
🚀 Merged !112515 (merged) Adds the API access we need for the more surgical data
We are here! 👉🏻 !112516 (merged) Switches to using our initial metadata representation of the MR for many operations
🛠 In Dev !111895 (merged) Adds the feature that will only load the proper file when necessary to display it

Screenshots or screen recordings

N/A, all backstage

How to set up and validate locally

There isn't really a way to verify this by using the application except in general terms:

  1. Go to an MR Changes (Diffs) tab and navigate around.
    1. Make sure the file tree is working.
    2. Make sure file-by-file navigation is working (showing the right total count, moving next/prev properly, etc.).
    3. Make sure that clicking on a file in the file tree (which adds it's hash to the URL) moves the UI to the right file.

You could also add some logging/breakpoints to the app and check that - when the app is working properly - it's also relying on these new meta files for most operations except when rendering the diffs themselves.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Thomas Randolph

Merge request reports