diff options
author | Lars Hjemli <hjemli@gmail.com> | 2008-11-30 00:46:37 (JST) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-11-30 00:46:37 (JST) |
commit | 8813170390f3c3a0f4743afbc92ede42953fa3b0 (patch) | |
tree | 39305350baee1eb564aae00294634bbe544983d3 /ui-repolist.c | |
parent | 54272e60965ec6a98b49cbf67d72a4b1f5adc55b (diff) | |
download | cgit-8813170390f3c3a0f4743afbc92ede42953fa3b0.zip cgit-8813170390f3c3a0f4743afbc92ede42953fa3b0.tar.gz |
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 <hjemli@gmail.com>
Diffstat (limited to 'ui-repolist.c')
-rw-r--r-- | ui-repolist.c | 16 |
1 files changed, 12 insertions, 4 deletions
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) | |||
32 | { | 32 | { |
33 | char *path; | 33 | char *path; |
34 | struct stat s; | 34 | struct stat s; |
35 | struct cgit_repo *r = (struct cgit_repo *)repo; | ||
35 | 36 | ||
37 | if (repo->mtime != -1) { | ||
38 | *mtime = repo->mtime; | ||
39 | return 1; | ||
40 | } | ||
36 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); | 41 | path = fmt("%s/%s", repo->path, ctx.cfg.agefile); |
37 | if (stat(path, &s) == 0) { | 42 | if (stat(path, &s) == 0) { |
38 | *mtime = read_agefile(path); | 43 | *mtime = read_agefile(path); |
44 | r->mtime = *mtime; | ||
39 | return 1; | 45 | return 1; |
40 | } | 46 | } |
41 | 47 | ||
42 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); | 48 | path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch); |
43 | if (stat(path, &s) == 0) { | 49 | if (stat(path, &s) == 0) |
44 | *mtime = s.st_mtime; | 50 | *mtime = s.st_mtime; |
45 | return 1; | 51 | else |
46 | } | 52 | *mtime = 0; |
47 | return 0; | 53 | |
54 | r->mtime = *mtime; | ||
55 | return (r->mtime != 0); | ||
48 | } | 56 | } |
49 | 57 | ||
50 | static void print_modtime(struct cgit_repo *repo) | 58 | static void print_modtime(struct cgit_repo *repo) |