Repository navigation
Add add-tag-to-commits feature - #2026
Conversation
add-tag-to-commits feature
The API only returns the Tag type on annotated tags and not lightweight ones for example: 123425d, and from what I've can tell you can't retrieve the tag name for the Github API. |
This works: https://stackoverflow.com/a/53923870/288906 Compared to the query in this PR: |
There was a problem hiding this comment.
Since we now have the cache, can you pick this up again?
It will need a couple of big changes:
- first look into the cache, they need to be stored as
commit: [tag, tag] - then query pages as needed
Perhaps generators would be useful here:
yield cache; // Record<string, string[]>
yield getPage(); // also needs to return the same format that's already cached
while hasNextPage
yield getPage(next page)and then progressively look for the current page's commits in the cache and then next pages, excluding them until:
- the pages are finished, or
- the
commitsOnPageis empty
commitsOnPage = select.all(...)
for (page /* one of which could be the cache */ of generator) {
for (commit of commitsOnPage) { // loop through remaining commits
if (page[commit]) {
// add tags from page[commit]
commitsOnPage.delete(commit)
}
}
}Thoughts?
Co-Authored-By: Federico Brigante <[email protected]>
|
I hate the concept of pages because there is no way to guarantee you get the same response in each request. Therefore caching based on pages would also be problematic, they would have to be very short-lived because the first page will always change anytime a new tag is created, otherwise the feature will become unreliable. Heres what I think:
commitsOnPage = select.all()
let tags = cache.get()
while (not all commitsOnPage in tags) {
tags = tags + getMoreTags()
}
cache.set(tags)
for (commit of commitsOnPage) {
// add tags[commit] to page
}Cons:
commitsOnPage = select.all()
for (commit of commitsOnPage) {
tag = cache.get(commit) // if the commit was found while fetching the previous commit it will be in the cache now
if (!tag) {
tag = getTagForCommit(commit)
}
// add tag to page
}
function getTagForCommit(commit) {
const tags = {};
while (!commitFound) {
tags = {...tags, apiCall()}
for (tag of tags) {
cache.set(tag)
}
if (tags[commit]) {
return tags[commit]
}
}
return []
} |
|
The cache would not be per page, but per commit: That doesn’t change. For every fetched page, you can extend the cache with new commit->tags matches. However… I just realized that neither of our solutions actually limits the pages fetched because both keep fetching pages until all the commits on the page are tagged… which is wrong. Not all commits will have a tag so the code will always fetch all the pages looking for a match. I guess this search would have to be even smarter and complicated because the search has to stop when it finds a tag that is on a commit older than what’s on the page. 🤷♂️ |
|
Unless you have a better idea, let’s keep it easy for now:
The cache should already have all the tags, except the very latest. When you fetch a page with tag already in the cache (i.e. overlap), it can stop fetching more pages. Also perhaps a “first run” should avoid any fetch if the current page is found “in the middle” of the cache. |
|
We can get the timestamp from tag/commit and also ask for the time of the last commit on the page: {
repository(owner: "sindresorhus", name: "refined-github") {
refs(first: 100, refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
pageInfo {
hasNextPage
endCursor
}
nodes {
name
target {
commitResourcePath
... on Tag {
tagger {
date
}
}
... on Commit {
committedDate
}
}
}
}
object(expression: "9b2acbbc0023c5df62c55b2595febd8277d652eb") {
... on Commit {
committedDate
}
}
}
}
If the date of the last commit is younger than the last tag then stop looking for tags? |
|
I didn’t think about the date, that works too. However I’m trying to find the least complex solution and maybe having to keep track of dates as well might be more complicated than the last solution I proposed. Thoughts? |
|
I'll try both and see which one works better. Found a possible problem in your solution, using nodejs/node as a test page, using the cache overlap solution you still will fetch all the pages. Comparing dates you will only fetch the first one. Both of them also share a problem but I don't know how major they will be: If we stumble upon a commit not in the cache, no matter what "page" the commit appears on, we will still have to fetch all pages leading up to that page. This should be minor unless you go back a few pages in the UI (I don't know why you would do this though.) Also, if there are two tags on the same commit separated by a page, there is a chance that only one of these tags will appear. |
|
@bfred-it Since we are keeping each commit as a separate cache entry, it would be nice to have a cache function to get/set multiple at the same time: Maybe convert our current API to mimic the native one while still adding expiration |
Good point, my solution will fetch all the pages at first to fill the cache, dates can allow us to be more selective.
Hmmm no, because as I suggested here we stop as soon as there's any overlap, we don't look for every commit.
My later solution fetches all the tags at first, it doesn't have this problem. A date-based solution would not suffer this problem either, unless this commit is the last on the current page (github.com) as well as the last tag on the current tag page (api). It's a rare occurrence, I'd say, especially considering how rarely a commit has multiple tags.
The cache should be grouped by repo because it's easier to get and set: cache.set('tags:sindresorhus/refined-github', {
'eb9feb9': ['v1'],
'a0ce6e6': ['v2', 'v2-beta']
});There's no way to query the storage by "key starts with abc:*" |
|
Okay so we're back to the two different solutions
|
|
Dates sound good, if the resulting code isn't too complex. Do you think you'll also have to store the commit date in the cache for this to work? cache.set('tags:sindresorhus/refined-github', {
'eb9feb9': {tags: ['v1'], date},
'a0ce6e6': {tags: ['v2', 'v2-beta'], date}
}); |
|
I have it working without storing the dates, but I also store when a commit has no tags: cache.set('tags:sindresorhus/refined-github', {
'eb9feb9': ['v1'],
'a0ce6e6': ['v2', 'v2-beta'],
'cc2c967': []
}); |
I thought about that, but wouldn't that get too heavy? Some repos have maaany commits. Let's see it, if you already wrote it |
I did this to avoid an API call if every commit is cached, the same effect can be achieved other ways I believe.
Yeah storing it in a single key would make it a little heavy, since when you add a key to it, it will basically never get expired. That's why I assumed we would keep a different key for each commit that way you can expire the commits that you no longer see.
I did 😃, cleaning up lint things |
Co-Authored-By: Jeroen van Warmerdam <[email protected]>
fregante
left a comment
There was a problem hiding this comment.
To collaborators: Feel free to merge if it passes your review
|
@dotconnor Can you fix the merge conflict? |
|
Thanks for working on this, @dotconnor 👌 |
|
This is pretty useful even to Refined GitHub, when looking at the commit log: |



Note: For some reason, the API returns empty data on some tags
Closes #807
IssueHunt Summary
Referenced issues
This pull request has been submitted to:
IssueHunt has been backed by the following sponsors. Become a sponsor