refactor: create MR cache
The motivation for this MR is best explained in #341 (closed).
TL;DR: Creating MR diff comments will require a lot of information about the MR, but VS Code doesn't provide a direct way to pass the information from the place where we fetch it (mr_item_model
which fetches the MR info when we click on an item in the left Tree View) to the place where we create the comments (a function that only gets the file URI as an argument).
This MR introduces a cache to make the MR information retrieval seamless. The following snippet captures the main contribution of this MR:
class WrappedRepository {
private mrCache: Record<number, CachedMr> = {};
async reloadMr(mr: RestIssuable): Promise<CachedMr> {
const mrVersion = await this.getGitLabService().getMrDiff(mr);
const cachedMr = {
mr,
mrVersion,
};
this.mrCache[mr.id] = cachedMr;
return cachedMr;
}
getMr(id: number): CachedMr | undefined {
return this.mrCache[id];
}
}
How to review this MR
This MR contains the main change + three refactoring commits preparing for the change. I recommend reviewing the MR commit-by-commit. The commit messages are very descriptive.
Related to #341 (closed)