Fix spurious requests

* It uses the patches and issues count on ProjectInfo to reduce the
  amount of requests that are made to the seed nodes.
* It also adds the Delegate type used as a property in the Project class
  mirroring the radicle_common::project::Delegate enum, which currently
  was only represented as a string[].
* Removes also the maintainers property which isn't used anymore, and
  adds the remotes property.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
Sebastian Martinez
2022-08-05 16:19:08 +02:00
committed by Alexis Sellier
parent 7ae5317b54
commit 0c2fbe0e48
3 changed files with 31 additions and 25 deletions
+3 -1
View File
@@ -12,5 +12,7 @@
]
}
],
"head": "56e4e029c294b08546386e1fb706b772c7433c49"
"head": "56e4e029c294b08546386e1fb706b772c7433c49",
"patches": 2,
"issues": 3
}
+8 -10
View File
@@ -8,8 +8,6 @@
import PeerSelector from "@app/base/projects/PeerSelector.svelte";
import type { Tree } from "@app/project";
import Input from "@app/Input.svelte";
import { groupIssues, Issue } from "@app/issue";
import { groupPatches, Patch } from "@app/patch";
export let project: Project;
export let tree: Tree;
@@ -210,30 +208,30 @@
on:click={() => toggleContent(ProjectContent.History, true)}>
<strong>{tree.stats.commits}</strong> commit(s)
</div>
{#await Issue.getIssues(project.urn, seed.api) then issues}
{#if project.issues > 0}
<div
class="stat issue-count clickable widget"
class:active={content == ProjectContent.Issues}
on:click={() => toggleContent(ProjectContent.Issues, false)}>
<strong>{groupIssues(issues).open.length}</strong> issue(s)
<strong>{project.issues}</strong> issue(s)
</div>
{:catch}
{:else}
<div class="stat issue-count not-allowed widget" title="Not supported">
0 issue(s)
</div>
{/await}
{#await Patch.getPatches(project.urn, seed.api) then patches}
{/if}
{#if project.patches > 0}
<div
class="stat patch-count clickable widget"
class:active={content == ProjectContent.Patches}
on:click={() => toggleContent(ProjectContent.Patches, false)}>
<strong>{groupPatches(patches).proposed.length}</strong> patch(es)
<strong>{project.patches}</strong> patch(es)
</div>
{:catch}
{:else}
<div class="stat patch-count not-allowed widget" title="Not supported">
0 patch(es)
</div>
{/await}
{/if}
<div class="stat contributor-count widget">
<strong>{tree.stats.contributors}</strong> contributor(s)
</div>
+20 -14
View File
@@ -6,12 +6,20 @@ import { isOid, isRadicleId } from '@app/utils';
import { Profile, ProfileType } from '@app/profile';
import { Seed } from '@app/base/seeds/Seed';
import type { Config } from '@app/config';
import type { Issue } from '@app/issue';
export type Urn = string;
export type PeerId = string;
export type Branches = { [key: string]: string };
export type Delegate = {
type: "indirect";
urn: Urn;
ids: PeerId[];
} | {
type: "direct";
id: PeerId;
};
export interface Anchor {
confirmed: true;
id: string;
@@ -47,8 +55,10 @@ export interface ProjectInfo {
name: string;
description: string;
defaultBranch: string;
maintainers: Urn[];
delegates: PeerId[];
delegates: Delegate[];
remotes: PeerId[];
patches: number;
issues: number;
}
export interface Tree {
@@ -247,13 +257,15 @@ export class Project implements ProjectInfo {
name: string;
description: string;
defaultBranch: string;
maintainers: Urn[];
delegates: PeerId[];
delegates: Delegate[];
remotes: PeerId[];
seed: Seed;
peers: Peer[];
branches: Branches;
profile: Profile | null;
anchors: string[];
patches: number;
issues: number;
constructor(urn: string, info: ProjectInfo, seed: Seed, peers: Peer[], branches: Branches, profile: Profile | null, anchors: string[]) {
this.urn = urn;
@@ -261,11 +273,13 @@ export class Project implements ProjectInfo {
this.name = info.name;
this.description = info.description;
this.defaultBranch = info.defaultBranch;
this.maintainers = info.maintainers;
this.delegates = info.delegates;
this.remotes = info.remotes;
this.seed = seed;
this.peers = peers;
this.branches = branches;
this.patches = info.patches;
this.issues = info.issues;
this.profile = profile;
this.anchors = anchors;
}
@@ -336,14 +350,6 @@ export class Project implements ProjectInfo {
return new Request(`projects/${this.urn}/commits/${commit}`, this.seed.api).get();
}
static async getIssues(urn: string, host: Host): Promise<Issue[]> {
return new Request(`projects/${urn}/issues`, host).get();
}
async getIssue(issue: string): Promise<Issue> {
return new Request(`projects/${this.urn}/issues/${issue}`, this.seed.api).get();
}
async getTree(
commit: string,
path: string,