]> gitweb.ps.run Git - ps-cgit/blobdiff - ui-repolist.c
ui-repolist: implement lazy caching of repo->mtime
[ps-cgit] / ui-repolist.c
index cf27cb3072a2cca564bac95f733fe5bfe489f901..aa743bf7885ab683e1b1e1b668d73d2477d7dd71 100644 (file)
@@ -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)