Visitar URL original
Add test case: Make sure, related topic is no unused topic by shaedrich · Pull Request #4016 · github/explore · GitHub
The Wayback Machine - https://web.archive.org/web/20240112040313/https://github.com/github/explore/pull/4016
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case: Make sure, related topic is no unused topic #4016

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

shaedrich
Copy link
Contributor

As per 7d2ffe5#r1069478838

Please confirm this pull request meets the following requirements:

Which change are you proposing?

  • Suggesting edits to an existing topic or collection
  • Curating a new topic or collection
  • Something that does not neatly fit into the binary options above

Editing an existing topic or collection

I'm suggesting these edits to an existing topic or collection:

  • Image (and my file is *.png, square, dimensions 288x288, size <= 75 kB)
  • Content (and my changes are in index.md)

Please replace this line with an explanation of why you think these changes should be made.

Curating a new topic or collection

  • I've formatted my changes as a new folder directory, named for the topic or collection as it appears in the URL on GitHub (e.g. https://github.com/topics/[NAME] or https://github.com/collections/[NAME])
  • My folder contains a *.png image (if applicable) and index.md
  • All required fields in my index.md conform to the Style Guide and API docs: https://github.com/github/explore/tree/main/docs

Please replace this line with an explanation of why you think this topic or collection should be curated.

Something that does not neatly fit into the binary options above

  • My suggested edits are not about an existing topic or collection, or at least not a single one
  • My suggested edits are not about curating a new topic or collection, or at least not a single one
  • My suggested edits conform to the Style Guide and API docs: https://github.com/github/explore/tree/main/docs

As per #3487 (comment)


Please note: we will close your PR without comment if you do not check the boxes above and provide ALL requested information.

@shaedrich shaedrich requested a review from a team as a code owner October 31, 2023 01:11
@shaedrich shaedrich marked this pull request as draft October 31, 2023 01:30
@shaedrich shaedrich marked this pull request as ready for review October 31, 2023 03:52
@shaedrich
Copy link
Contributor Author

shaedrich commented Oct 31, 2023 •

fyi: The test is supposed to fail since there are actually a few related topics that don't have a single repository. Will be fixed in and should ideally be merged alongside with #4018

Copy link
Contributor

@kenyonj kenyonj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was initially implemented because we were using the Octokit REST api endpoints, 1 call for each repo/user we were checking. Then I moved things over to make 1 graphql api call for every item in a collection. Is there something similar that we could do with topics?

test/topics_test.rb Outdated Show resolved Hide resolved
Comment on lines +113 to +123
def topic(name)
return topics[name] if topics.key?(name)
topics[name] = client.search_repositories("topic:#{name}").total_count > 0
@@topic_request_count += 1
sleep client.rate_limit.resets_in if client.rate_limit.remaining == 0
topics[name]
rescue Octokit::TooManyRequests
topics[:skip_requests] = true
topics[name] = true
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the idea here. However, I'm not sure that we want to sleep until the rate limit resets. I am not sure how long that cycle usually lasts, but we'll have to pay that price on all PRs after a rate limit is hit.

What if instead of sleeping, we set the skip_requests value when we hit 0?

Suggested change
def topic(name)
return topics[name] if topics.key?(name)
topics[name] = client.search_repositories("topic:#{name}").total_count > 0
@@topic_request_count += 1
sleep client.rate_limit.resets_in if client.rate_limit.remaining == 0
topics[name]
rescue Octokit::TooManyRequests
topics[:skip_requests] = true
topics[name] = true
end
def topic(name)
return topics[name] if topics.key?(name)
if client.rate_limit.remaining > 0
@@topic_request_count += 1
topics[name] = client.search_repositories("topic:#{name}").total_count > 0
else
topics[:skip_requests] = true
topics[name] = true
end
topics[name]
rescue Octokit::TooManyRequests
topics[:skip_requests] = true
topics[name] = true
end

The rescue might be redundant in this case, but I'm leaving it in there to match what we're doing in other places. Although, I like this pattern better. If you had the time to modify the rest of the methods to match this, and if it works, I'd be +1 for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, what skip_requests does, is to only check topics until the rate limit is reached and leave the rest unchecked, so we don't have to wait? Doesn't sound very trustworthy to me, to be honest. However, this might be solved by a GraphQL implementation—I definitely look into that!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wrote all this a very long time ago and I think I was doing it so that we could simply get passed the failing checks, then I swapped over to the graphql stuff and all of this was no longer a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's definitely possible via GraphQL. I'm implementing it right now. Stay tuned!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grafik
My assumption is, that 1289 topics might be too much for the API—can that be the reason? If it's not, the error message isn't hinting at anything specifically ^^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong. I did a little fiddling, and it turns out that the API doesn't expect the topic's repositories property to be accessed if it's not curated. Is there a way around?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can access the totalCount on the repositories property for topics that don't have any repos still:

query {
  topic(name:"kart-racing") {
    repositories{
      totalCount
    }
    relatedTopics {
      id
    }
  }
}

result:

{
  "data": {
    "topic": {
      "repositories": {
        "totalCount": 0
      },
      "relatedTopics": []
    }
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you are right. My query was:

query {
  config: topic(name:"config") {
    repositories{
      totalCount
    }
    relatedTopics {
      id
    }
  }
}

But it's not that 5,819,971 repositories might be too much, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anyone have any idea what's so special about "config"?

@shaedrich shaedrich marked this pull request as draft November 7, 2023 07:26
@ahpook
Copy link
Contributor

ahpook commented Nov 27, 2023

I couldn't quite follow whether the conversation on the test changes resolved to a good state - @kenyonj can you take a quick peek and merge if you're happy? Thx

@shaedrich
Copy link
Contributor Author

@ahpook No, unfortunately, there's still a problem with the topic "config" and I just can't figure out why—it doesn't seem to be a reserved word or the like.

#4016 (comment)

cole67

This comment was marked as spam.

@shaedrich
Copy link
Contributor Author

@ahpook I excluded config topic for now and now it magically works 🤷🏻

@shaedrich shaedrich marked this pull request as ready for review January 3, 2024 07:29
@shaedrich shaedrich requested a review from kenyonj January 3, 2024 07:33
# carry.merge(related_topics)
#end
#cache_topics_exist_check!(all_related_topics)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to stay commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I only knew 😅

If in doubt, this apparently can be deleted 🤷🏻‍♂️

Copy link
Contributor Author

@shaedrich shaedrich Jan 3, 2024 •

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still used in https://github.com/shaedrich/explore/blob/topics_test/test/topics_test.rb#L168, so I suppose, that's okay 🤔

@ahpook
Copy link
Contributor

ahpook commented Jan 3, 2024

Classic Ruby stuff 💎

@shaedrich
Copy link
Contributor Author

@ahpook I excluded config topic for now and now it magically works 🤷🏻

Should we worry about that or are we fine without config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants