[PATCH 05 of 15] speedy: create an index used to speed up 'author' revset query
Augie Fackler
raf at durin42.com
Wed Dec 12 21:28:21 CST 2012
On Dec 11, 2012, at 12:38 PM, Tomasz Kleczek <tkleczek at fb.com> wrote:
> # HG changeset patch
> # User Tomasz Kleczek <tkleczek at fb.com>
> # Date 1355246587 28800
> # Branch stable
> # Node ID 6013a399d9b4cad8578b587084ed0eb6a8080f5b
> # Parent e9e1263a5d57cb07fb2f0176163325bd185a3666
> speedy: create an index used to speed up 'author' revset query
>
> To accelerate history queries server builds data structures in form
> of key-value mappings which are referred to as `indices`.
>
> To simplify the desin we assume that the indices are read-only during
typo: design
> the server operation. The server update is meant to be updated in these steps:
> 1. stop the serverrepo server
> 1. stop the history server
> 2. pull new changes into the serverrepo
[...]
> --- /dev/null
> +++ b/hgext/speedy/index.py
> @@ -0,0 +1,24 @@
> +# Copyright 2012 Facebook
> +#
> +# This software may be used and distributed according to the terms of the
> +# GNU General Public License version 2 or any later version.
> +
> +"""Indice definitions.
Index
> +
> +Indices are data structures in the form of key-value mappings used
> +by the server to speed up computations.
> +"""
> +
> +def makeuserchgs(ctxs):
> + """Return the `userchgs` index in the form of a dict
> +
> + `userchgs` is keyed by username, with each value being a list
> + of changes commited by that user.
> +
> + ctxs: an iterable with change contexts from which the index is to
> + be created.
> + """
> + newentries = {}
> + for ctx in ctxs:
> + newentries.setdefault(ctx.user(), []).append(ctx.node())
> + return newentries
> diff --git a/hgext/speedy/server.py b/hgext/speedy/server.py
> --- a/hgext/speedy/server.py
> +++ b/hgext/speedy/server.py
> @@ -9,12 +9,16 @@
> """
>
> from mercurial import revset
> +from mercurial import encoding
> +import index
>
> class metaserver(object):
> """Contains all the logic behind the query acceleration."""
>
> - def __init__(self, repo):
> + def __init__(self, repo, indices):
> self.repo = repo
> + for name, idx in indices.iteritems():
> + setattr(self, name, idx)
>
> def author(self, pat):
> """Return a list of changes commited by a user that matches pattern.
> @@ -24,10 +28,24 @@
>
> Returns a list of node ids.
> """
> - # This is going to be accelerated in the subsequent patches
> - revs = revset.author(self.repo, list(self.repo), ('symbol', pat))
> - return [self.repo[r].node() for r in revs]
> + pat = encoding.lower(pat)
> + kind, pattern, matcher = revset._substringmatcher(pat)
> + nodecands = []
> + for user, l in self.userchgs.iteritems():
> + if matcher(encoding.lower(user)):
> + nodecands.extend(l)
> + return nodecands
> +
> +indicecfg = {
> + 'userchgs': index.makeuserchgs,
> +}
>
> def makeserver(repo):
> - """Return an initialized metaserver instance."""
> - return metaserver(repo)
> + """Return an initialized metaserver instance.
> +
> + Update the indices to the most recent revision along the way.
> + """
> + ctxs = [repo[r] for r in xrange(0, len(repo))]
> + indices = dict([(name, create(ctxs)) for name, create in
> + indicecfg.iteritems()])
> + return metaserver(repo, indices)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list