Skip to content

Add contributors view in repo sidebar#37146

Draft
bircni wants to merge 2 commits intogo-gitea:mainfrom
bircni:feature/add-contributors-view
Draft

Add contributors view in repo sidebar#37146
bircni wants to merge 2 commits intogo-gitea:mainfrom
bircni:feature/add-contributors-view

Conversation

@bircni
Copy link
Copy Markdown
Member

@bircni bircni commented Apr 8, 2026

Adds a contributors view as GitHub has in the repo sidebar

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 8, 2026
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/frontend labels Apr 8, 2026
{{else}}
<span data-tooltip-content="{{.Name}}">
<img class="ui avatar" src="{{.AvatarLink}}" alt="{{.Name}}">
</span>
Copy link
Copy Markdown
Member

@silverwind silverwind Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use existing avatar template helpers, same as should be used in issue list or elsewhere.

Also I recommend setting a explicit size=32 parameter on it to make the backend return downsized avatars.

border-radius: 50%;
width: 100%;
aspect-ratio: 1;
}
Copy link
Copy Markdown
Member

@silverwind silverwind Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule should removed and it should use global avatar styles (if they exist). And we don't do fully-round avatars (design choice).

@silverwind
Copy link
Copy Markdown
Member

Does it have performance impact?

Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, you will know that the design is not feasible if you look into the details of GetContributorStats, especially on a heavy server which has a lot of large repos.

Although GitHub shows the contributors, I am sure it uses a much better approach to avoid performance problem.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 8, 2026
@a1012112796
Copy link
Copy Markdown
Member

Yes, at lest should lazy loading like previous usage.

async fetchGraphData() {
this.isLoading = true;
try {
let response: Response;
do {
response = await GET(`${this.repoLink}/activity/contributors/data`);
if (response.status === 202) {
await sleep(1000); // wait for 1 second before retrying
}
} while (response.status === 202);
if (response.ok) {
const data = await response.json() as ContributorsData;
const {total, ...other} = data;
// below line might be deleted if we are sure go produces map always sorted by keys
total.weeks = Object.fromEntries(Object.entries(total.weeks).sort());

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Apr 9, 2026

lazy loading

That's one solution but I think it's not ideal because of content pop-in. A ideal solution would be the have some server-side cache. I think the contributor stats already have some form of cache, maybe it can even be re-used, this user list can be built off the same data (top contributors sorted by contributions).

@wxiaoguang
Copy link
Copy Markdown
Contributor

No, the problem is more complex than a simple cache.

I don't know whether you have benchmarked the related function. On my side, GetContributorStats takes about 20 seconds on gitea's git repo.

So, suppose you have 30 gitea-like (or even larger) git repositories, and these repositories are viewed frequently (say, a large server), then GetContributorStats will keep running the git command and take up 100% CPU for all time.

@silverwind
Copy link
Copy Markdown
Member

Could be made an intelligent cache. On repo page with stale cache, run in background and don't show it initially, only when available and non-stale. On stats page run it synchronously via fetch (long loading state, same as GitHub).

That's at least how it works on GitHub. Another option is to have a scheduled background cron job, but that'll be more work overall for the server as it has to do it for all repos regardless whether they are being visited.

@wxiaoguang
Copy link
Copy Markdown
Contributor

If let me guess, I would say GitHub uses a database-based incremental "contributor counter". If any push always triggers the re-calculation of the "contributor stats", it is unlikely a feasible solution for a large repo like Linux kernel.

@TheFox0x7
Copy link
Copy Markdown
Contributor

TheFox0x7 commented Apr 9, 2026

Actually isn't that function racy? If the generation takes up a bit (like the 20 seconds you mentioned) wouldn't few users hitting it create multiple git processes as each is trying to fill the cache that does not exist yet?

If any push always triggers the re-calculation of the "contributor stats", it is unlikely a feasible solution for a large repo like Linux kernel.

Yeah it takes on my HW about 4 minutes to run getExtendedCommitStats git command and I've limited it to be from 2022 in the first place.

I think push could just append to the database table, but then it's an issue with force-pushes afaik (plus memory issue I've ran into while looking at secret scanning). I haven't thought about this in a while though.

@a1012112796
Copy link
Copy Markdown
Member

So, suppose you have 30 gitea-like (or even larger) git repositories, and these repositories are viewed frequently (say, a large server), then GetContributorStats will keep running the git command and take up 100% CPU for all time.

so, looks it's an exist issue? How about add a queue to do generateContributorStats?

@silverwind
Copy link
Copy Markdown
Member

silverwind commented Apr 9, 2026

If let me guess, I would say GitHub uses a database-based incremental "contributor counter".

Can't be. Visiting <repo>/graphs/contributors often loads many minutes for me on some repos. I think it's a cache like I described.

@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Apr 9, 2026

So, suppose you have 30 gitea-like (or even larger) git repositories, and these repositories are viewed frequently (say, a large server), then GetContributorStats will keep running the git command and take up 100% CPU for all time.

so, looks it's an exist issue? How about add a queue to do generateContributorStats?

The problem is there, but it doesn't really cause issue at the moment (unless some malicious users try to DoS a server).

At the moment, "GetContributorStats" is only called by fetch in the "Activity" sub-page, not the repo's home page.

I don't see a simple "queue" could really help the problem either.

@wxiaoguang
Copy link
Copy Markdown
Contributor

Actually isn't that function racy? If the generation takes up a bit (like the 20 seconds you mentioned) wouldn't few users hitting it create multiple git processes as each is trying to fill the cache that does not exist yet?

There is also a lock in GetContributorStats

@TheFox0x7
Copy link
Copy Markdown
Contributor

Actually isn't that function racy? If the generation takes up a bit (like the 20 seconds you mentioned) wouldn't few users hitting it create multiple git processes as each is trying to fill the cache that does not exist yet?

There is also a lock in GetContributorStats

Indeed there is and I missed it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged modifies/frontend modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants