Skip to content
Permalink
Browse files
[webkitscmpy] Share cache between processes
https://bugs.webkit.org/show_bug.cgi?id=231176
<rdar://problem/83841221>

Reviewed by Dewei Zhu.

Generating the identifier cache is more expensive than reading a file with
that cache in it. This is particularly relevant for webservers, which are
likely running multiple processes.

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git.Cache.__init__): Move cache loading into "load" function.
(Git.Cache.load): Open cache file.
(Git.Cache.to_hash): If we fail to find a match, attempt to load the file
before populating the file.
(Git.Cache.to_revision): Ditto.
(Git.Cache.to_identifier): Ditto.


Canonical link: https://commits.webkit.org/242673@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283751 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Oct 7, 2021
1 parent 28e9d03 commit 010340ed3779b7c1737cfe2d4edf45cfe0ccaf4a
Showing 4 changed files with 57 additions and 14 deletions.
@@ -1,3 +1,27 @@
2021-10-07 Jonathan Bedard <jbedard@apple.com>

[webkitscmpy] Share cache between processes
https://bugs.webkit.org/show_bug.cgi?id=231176
<rdar://problem/83841221>

Reviewed by Dewei Zhu.

Generating the identifier cache is more expensive than reading a file with
that cache in it. This is particularly relevant for webservers, which are
likely running multiple processes.

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitscmpy/setup.py: Bump version.
* Scripts/libraries/webkitscmpy/webkitscmpy/__init__.py: Ditto.
* Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:
(Git.Cache.__init__): Move cache loading into "load" function.
(Git.Cache.load): Open cache file.
(Git.Cache.to_hash): If we fail to find a match, attempt to load the file
before populating the file.
(Git.Cache.to_revision): Ditto.
(Git.Cache.to_identifier): Ditto.

2021-10-07 Jonathan Bedard <jbedard@apple.com>

[contributors.json] Relocation (Part 7)
@@ -29,7 +29,7 @@ def readme():

setup(
name='webkitscmpy',
version='2.2.4',
version='2.2.5',
description='Library designed to interact with git and svn repositories.',
long_description=readme(),
classifiers=[
@@ -46,7 +46,7 @@ def _maybe_add_webkitcorepy_path():
"Please install webkitcorepy with `pip install webkitcorepy --extra-index-url <package index URL>`"
)

version = Version(2, 2, 4)
version = Version(2, 2, 5)

AutoInstall.register(Package('fasteners', Version(0, 15, 0)))
AutoInstall.register(Package('monotonic', Version(1, 5)))
@@ -49,6 +49,9 @@ def __init__(self, repo, guranteed_for=10):
self._last_populated = {}
self._guranteed_for = guranteed_for

self.load()

def load(self):
if not os.path.exists(self.path):
return

@@ -204,12 +207,16 @@ def to_hash(self, revision=None, identifier=None, populate=True, branch=None):
_, b_count, branch = parts
if b_count < 0:
return None
if branch not in self._ordered_commits or len(self._ordered_commits[branch]) <= b_count:
if populate:
self.populate(branch=branch)
return self.to_hash(identifier=identifier, populate=False)
return None
return self._ordered_commits[branch][b_count]
if branch in self._ordered_commits and len(self._ordered_commits[branch]) > b_count:
return self._ordered_commits[branch][b_count]

self.load()
if branch in self._ordered_commits and len(self._ordered_commits[branch]) > b_count:
return self._ordered_commits[branch][b_count]
if populate:
self.populate(branch=branch)
return self.to_hash(identifier=identifier, populate=False)
return None

def to_revision(self, hash=None, identifier=None, populate=True, branch=None):
if hash:
@@ -221,16 +228,24 @@ def to_revision(self, hash=None, identifier=None, populate=True, branch=None):
_, b_count, branch = parts
if b_count < 0:
return None
if branch not in self._ordered_revisions or len(self._ordered_revisions[branch]) <= b_count:
if populate:
self.populate(branch=branch)
return self.to_revision(identifier=identifier, populate=False)
return None
return self._ordered_revisions[branch][b_count]
if branch in self._ordered_revisions and len(self._ordered_revisions[branch]) > b_count:
return self._ordered_revisions[branch][b_count]

self.load()
if branch in self._ordered_revisions and len(self._ordered_revisions[branch]) > b_count:
return self._ordered_revisions[branch][b_count]
if populate:
self.populate(branch=branch)
return self.to_revision(identifier=identifier, populate=False)
return None

def to_identifier(self, hash=None, revision=None, populate=True, branch=None):
revision = Commit._parse_revision(revision, do_assert=False)
if revision:
if revision in self._revisions_to_identifiers:
return self._revisions_to_identifiers[revision]

self.load()
if revision in self._revisions_to_identifiers:
return self._revisions_to_identifiers[revision]
if populate:
@@ -244,7 +259,11 @@ def to_identifier(self, hash=None, revision=None, populate=True, branch=None):
candidate = self._hash_to_identifiers.get(hash)
except KeyError: # Means the hash wasn't specific enough
return None
if candidate:
return candidate

self.load()
candidate = self._hash_to_identifiers.get(hash)
if candidate:
return candidate
if populate:

0 comments on commit 010340e

Please sign in to comment.