summaryrefslogtreecommitdiff
path: root/src/odb_pack.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-07-22 13:34:19 -0400
committerEdward Thomson <ethomson@github.com>2016-08-04 15:12:04 -0400
commit27051d4e3134e53096b10089654a965064a77403 (patch)
tree8954ca3d25e96ebaf252d4e05de78f74ca46b591 /src/odb_pack.c
parent8f09a98e1809dcdfd9d25b8268657bac4d942e6a (diff)
downloadlibgit2-ethomson/refresh_objects.tar.gz
odb: only freshen pack files every 2 secondsethomson/refresh_objects
Since writing multiple objects may all already exist in a single packfile, avoid freshening that packfile repeatedly in a tight loop. Instead, only freshen pack files every 2 seconds.
Diffstat (limited to 'src/odb_pack.c')
-rw-r--r--src/odb_pack.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 3b52b6be6..b80d0337a 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -20,6 +20,9 @@
#include "git2/odb_backend.h"
+/* re-freshen pack files no more than every 2 seconds */
+#define FRESHEN_FREQUENCY 2
+
struct pack_backend {
git_odb_backend parent;
git_vector packs;
@@ -367,12 +370,22 @@ static int pack_backend__freshen(
git_odb_backend *backend, const git_oid *oid)
{
struct git_pack_entry e;
+ time_t now;
int error;
if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0)
return error;
- return git_futils_touch(e.p->pack_name);
+ now = time(NULL);
+
+ if (e.p->last_freshen > now - FRESHEN_FREQUENCY)
+ return 0;
+
+ if ((error = git_futils_touch(e.p->pack_name, &now)) < 0)
+ return error;
+
+ e.p->last_freshen = now;
+ return 0;
}
static int pack_backend__read(