~edwargix/git.sr.ht

b2ddc75f0b66debe09b7c6af4837b7817a1a018d — наб 4 years ago 2e9afc6
Run GC in gitsrht-periodic

This doesn't run gc --aggressive at all, which git-gc(1) says should be
run occasionally and provides long-lasting benefits, but it's a step
in the right direxion

Ref: ~sircmpwn/git.sr.ht#166
1 files changed, 21 insertions(+), 0 deletions(-)

M gitsrht-periodic
M gitsrht-periodic => gitsrht-periodic +21 -0
@@ 1,4 1,8 @@
#!/usr/bin/env python3
import math
import random
import sqlalchemy as sa
import subprocess
from srht.config import cfg
from srht.database import DbSession
from gitsrht.repos import GitRepoApi


@@ 21,4 25,21 @@ def cleanup_autocreated():
      db.session.delete(r)
    db.session.commit()

def gc():
    repo_count = Repository.query.count()

    # *srht-periodic scripts are run every twenty minutes,
    # this gives us 504 runs over the course of a week;
    # hence, if we GC a 504th of the repository count each time,
    # on average, we will have GCd every repo around once a week.
    limit = int(math.ceil(repo_count / (7 * 24 * 60 / 20)))

    repos = (Repository.query
            .offset(random.randrange(0, repo_count + 1 - limit))
            .limit(limit)).all()
    for r in repos:
        subprocess.run(["git", "-C", r.path, "gc", "--quiet"],
            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

cleanup_autocreated()
gc()