From 8813170390f3c3a0f4743afbc92ede42953fa3b0 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Sat, 29 Nov 2008 16:46:37 +0100 Subject: ui-repolist: implement lazy caching of repo->mtime When sorting the list of repositories by their last modification time, cgit would (in the worst case) invoke fstat(3) four times and open(3) twice for each callback from qsort(3). This obviously scales very badly. Now, the calculated modtime for each repo is saved in repo->mtime, thus keeping the number of stat/open invocations identical for sorted and unsorted repo-listings. Signed-off-by: Lars Hjemli --- cgit.h | 1 + shared.c | 1 + ui-repolist.c | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cgit.h b/cgit.h index ea90833..c99d337 100644 --- a/cgit.h +++ b/cgit.h @@ -61,6 +61,7 @@ struct cgit_repo { int snapshots; int enable_log_filecount; int enable_log_linecount; + time_t mtime; }; struct cgit_repolist { diff --git a/shared.c b/shared.c index f5875e4..89d1bab 100644 --- a/shared.c +++ b/shared.c @@ -60,6 +60,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->enable_log_linecount = ctx.cfg.enable_log_linecount; ret->module_link = ctx.cfg.module_link; ret->readme = NULL; + ret->mtime = -1; return ret; } diff --git a/ui-repolist.c b/ui-repolist.c index cf27cb3..aa743bf 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -32,19 +32,27 @@ static int get_repo_modtime(const struct cgit_repo *repo, time_t *mtime) { char *path; struct stat s; + struct cgit_repo *r = (struct cgit_repo *)repo; + if (repo->mtime != -1) { + *mtime = repo->mtime; + return 1; + } path = fmt("%s/%s", repo->path, ctx.cfg.agefile); if (stat(path, &s) == 0) { *mtime = read_agefile(path); + r->mtime = *mtime; return 1; } path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); - if (stat(path, &s) == 0) { + if (stat(path, &s) == 0) *mtime = s.st_mtime; - return 1; - } - return 0; + else + *mtime = 0; + + r->mtime = *mtime; + return (r->mtime != 0); } static void print_modtime(struct cgit_repo *repo) -- cgit 1.4.1 >png.h (unfollow)
Commit message (Expand)Author
2025-12-26Add ability to specify chemistryJune McEnroe
2025-12-22Expand regular expressionJune McEnroe
2025-12-22Let -n prevent postingJune McEnroe
2025-12-22Dehtml pronoun fieldsJune McEnroe
2025-12-10Add Rose/HouseJune McEnroe
2025-11-19Bilingualize pronouns regexJune McEnroe
2025-11-19Hardcode a follower IDJune McEnroe
2025-11-18Add pronouns bot scriptJune McEnroe
2025-08-27Update DESCRIPTION of myselfJune McEnroe
2025-08-18Publish "time"June McEnroe
2025-08-18Add a bunch of film roll metadataJune McEnroe
2025-08-18Add a draftJune McEnroe