Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita246889

Browse files
committed
Simple cache for URL building.
If someone uses this module for a long enough period of time, it is likelythat they will end up having to rebuild the same URL more than once. Thisshould speed up any subsequent calls for it.If a problem arises from this, I may end up using a caching module to evictold/unused cache entries, but I somehow doubt this will cause problems at all.
1 parent23f6dc7 commita246889

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

‎github3/models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
fromjsonimportdumps
1111
fromrequestsimportsession
1212

13+
__url_cache__= {}
14+
1315

1416
classGitHubObject(object):
1517
"""The :class:`GitHubObject <GitHubObject>` object. A basic class to be
@@ -105,7 +107,10 @@ def _build_url(self, *args, **kwargs):
105107
"""Builds a new API url from scratch."""
106108
parts= [kwargs.get('base_url')orself._github_url]
107109
parts.extend(args)
108-
return'/'.join(parts)
110+
key=tuple(parts)
111+
ifnotkeyin__url_cache__:
112+
__url_cache__[key]='/'.join(parts)
113+
return__url_cache__[key]
109114

110115
@property
111116
defratelimit_remaining(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp