# HG changeset patch # User Jun Wu <qu...@fb.com> # Date 1486604289 28800 # Wed Feb 08 17:38:09 2017 -0800 # Node ID 79adf3722f1b0f602e9461f13fa940a25dbfce56 # Parent 88c498ad9318df115d8408412a38edbac7d92a6a # Available At https://bitbucket.org/quark-zju/hg-draft # hg pull https://bitbucket.org/quark-zju/hg-draft -r 79adf3722f1b chgcache: add the background preloading thread
This patch adds the background preloading thread that runs in the chg master process. It reads and drains the IPC channel, but does not actually preload anything yet. diff --git a/hgext/chgcache.py b/hgext/chgcache.py --- a/hgext/chgcache.py +++ b/hgext/chgcache.py @@ -14,4 +14,5 @@ from __future__ import absolute_import import socket import sys +import threading import time @@ -77,4 +78,5 @@ class socketipc(object): _ipc = socketipc() +_repocaches = {} # {repopath: (mtime, cache)} # -- only used by the forked worker process ----------------------------------- @@ -94,4 +96,19 @@ def _runcommand(orig, self): return result +# -- only used by the master process ------------------------------------------ + +def _backgroundpreloader(interval=0.5): + while True: + try: + atime, path = _ipc.recv().split(' ', 1) + except Exception: # format error + pass + else: + if path in _repocaches and _repocaches[path][0] >= atime: + # the repo cache is up-to-date + continue + now = time.time() + _repocaches[path] = (now, None) + # ----------------------------------------------------------------------------- @@ -109,2 +126,8 @@ def extsetup(ui): caps = chgserver.chgcmdserver.capabilities caps['runcommand'] = extensions.bind(_runcommand, caps['runcommand']) + + # start the background preloader + t = threading.Thread(target=_backgroundpreloader, + name='chgcache-backgroundpreloader') + t.daemon = True + t.start() _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel