Pygithub: 검색당 κ²°κ³ΌλŠ” 1000개둜 μ œν•œλ©λ‹ˆλ‹€.

에 λ§Œλ“  2018λ…„ 06μ›” 21일  Β·  5μ½”λ©˜νŠΈ  Β·  좜처: PyGithub/PyGithub

GitHub API λŠ” 검색을 1000개의 결과둜 μ œν•œν•©λ‹ˆλ‹€ . 이 μ œν•œμ€ GitHub.search_issues 와 같이 PyGitHub λ₯Ό 톡해 μˆ˜ν–‰λ˜λŠ” 검색에 영ν–₯을 μ€λ‹ˆλ‹€.

κ·€ν•˜μ˜ 검색이 이 ν•œλ„μ— λ„λ‹¬ν–ˆλ‹€λŠ” ν‘œμ‹œκ°€ μ—†λŠ” 것 κ°™μŠ΅λ‹ˆλ‹€. μ œκ°€ μ•Œκ³  μžˆλŠ” μ˜ˆμ™Έλ‚˜ 였λ₯˜λŠ” μ—†μŠ΅λ‹ˆλ‹€. μ•„λ§ˆλ„ 이런 일이 λ°œμƒν–ˆμ„ λ•Œ μ˜ˆμ™Έκ°€ λ°œμƒν•΄μ•Ό ν•©λ‹ˆλ‹€(탐지할 수 μžˆλŠ” 경우).

μ—¬λŸ¬ 검색 쿼리λ₯Ό μ‹€ν–‰ν•˜μ—¬ 이 μ œν•œμ„ ν•΄κ²°ν•  수 μžˆμ§€λ§Œ μ΄λŸ¬ν•œ μΏΌλ¦¬λŠ” 쿼리의 νŠΉμ • λͺ©ν‘œμ— 맞게 μ‘°μ •λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€(예: 점진적 λ‚ μ§œ λ²”μœ„λ‘œ search_issues 반볡). 이λ₯Ό μΌλ°˜ν™”ν•  방법이 μƒκ°λ‚˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

이 문제λ₯Ό ν•΄κ²°ν•˜λŠ” 방법에 λŒ€ν•œ 생각이 μžˆμŠ΅λ‹ˆκΉŒ? 일반적인 해결책이 μžˆμŠ΅λ‹ˆκΉŒ?

이 λ¬Έμ œλŠ” 결과의 속도 μ œν•œ λ˜λŠ” νŽ˜μ΄μ§€ 맀김과 관련이 μ—†μŠ΅λ‹ˆλ‹€.

stale

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

이 문제λ₯Ό λ‹€μ‹œ μ—¬μ‹œκ² μŠ΅λ‹ˆκΉŒ?
λ‹€λ₯Έ 검색에 λŒ€ν•œ 일반적인 μ†”λ£¨μ…˜λ„

λͺ¨λ“  5 λŒ“κΈ€

λ‹€μŒμ€ 1000개 μ΄μƒμ˜ κ²°κ³Όκ°€ μžˆλŠ” κ²½μš°μ—λ„ λ‚ μ§œ λ²”μœ„μ˜ λͺ¨λ“  pull μš”μ²­μ„ κ²€μƒ‰ν•˜λŠ” 방법을 λ³΄μ—¬μ£ΌλŠ” ν•΄κ²° λ°©λ²•μž…λ‹ˆλ‹€.

νŽΈμ§‘: λ‚˜λŠ” 이것을 ν΄λž˜μŠ€λ³΄λ‹€ 더 κ°„λ‹¨ν•˜κ²Œ λ§Œλ“œλŠ” λ°©λ²•μœΌλ‘œ λ‹€μ‹œ μž‘μ„±ν•  κ²ƒμž…λ‹ˆλ‹€.

class PullRequestQuery:
    def __init__(self, git, repo, since, until):
        self.git = git
        self.repo = repo
        self.until = until
        self.issues = self.__query(since, until)

    def __iter__(self):
        skip = False
        while True:
            results = False
            for issue in self.issues:
                if not skip:
                    results = True
                    yield issue.as_pull_request()
                skip = False

            # If no more results then stop iterating.
            if not results:
                break

            # Start new query picking up where we left off. Previous issue will be first one returned, so skip it.
            self.issues = self.__query(issue.closed_at.strftime('%Y-%m-%dT%H:%M:%SZ'), self.until)
            skip = True

    def __query(self, since, until):
        querystring = 'type:pr is:closed repo:%s/%s closed:"%s..%s"' % (self.repo.organization.login, self.repo.name, since, until)
        return self.git.search_issues(query=querystring, sort="updated", order="asc")

이 클래슀λ₯Ό μ‚¬μš©ν•˜λ©΄ 이제 λ‹€μŒκ³Ό 같은 μž‘μ—…μ„ μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

git = Github(user, passwd)
org = git.get_organization(orgname)
repo = org.get_repo(reponame)
for pull in PullRequestQuery(git, repo, "2017-01-01", "2017-12-31"):
    print "%s: %s" % (pull.number, pull.title)

검색에 λŒ€ν•œ Github API λ¬Έμ„œλ₯Ό 읽으면 PyGithubμ—μ„œ 검색 κ²°κ³Ό ν”„λ‘œμ„ΈμŠ€μ˜ μΌλΆ€λ‘œ incomplete_results κ°€ λˆ„λ½λ˜μ—ˆμŒμ„ μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€. μ•„λ§ˆλ„ ν•΄λ‹Ή 값을 ν¬ν•¨ν•˜λ©΄ 검색 κ²°κ³Όκ°€ (뢈)μ™„μ „ν•œμ§€ μ—¬λΆ€λ₯Ό κ°μ§€ν•˜λŠ” 데 이미 도움이 될 수 μžˆμŠ΅λ‹ˆλ‹€.

이제 PyGithub이 λΆ„κΈ°λ˜μ–΄ μ†ŒμŠ€μ—μ„œ 둜컬둜 μ‹€ν–‰λ˜μ—ˆμœΌλ―€λ‘œ(#606을 보고 μžˆμŠ΅λ‹ˆλ‹€) μ•„λ§ˆλ„ 이것을 더 쑰사할 수 μžˆμŠ΅λ‹ˆλ‹€.

이 λ¬Έμ œλŠ” 졜근 ν™œλ™μ΄ μ—†μ—ˆκΈ° λ•Œλ¬Έμ— μžλ™μœΌλ‘œ 였래된 κ²ƒμœΌλ‘œ ν‘œμ‹œλ˜μ—ˆμŠ΅λ‹ˆλ‹€. 더 이상 ν™œλ™μ΄ μ—†μœΌλ©΄ νμ‡„λ©λ‹ˆλ‹€. κ·€ν•˜μ˜ 기여에 κ°μ‚¬λ“œλ¦½λ‹ˆλ‹€.

이 문제λ₯Ό λ‹€μ‹œ μ—¬μ‹œκ² μŠ΅λ‹ˆκΉŒ?
λ‹€λ₯Έ 검색에 λŒ€ν•œ 일반적인 μ†”λ£¨μ…˜λ„

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰