Skip to content

Commit 90da649

Browse files
niccokunzmannclaude
andcommitted
Read the review threads read before all pages were read again, once
Item.THREADS is the version of reading the threads; pull requests read with the first pages only (version 0) are read again by the next fetch, and the estimate counts them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 58f6e2b commit 90da649

7 files changed

Lines changed: 54 additions & 6 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.18 on 2026-11-25 23:56
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('community', '0014_suggestions'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='item',
15+
name='threads_version',
16+
field=models.PositiveSmallIntegerField(default=0),
17+
),
18+
]

‎community_insights/models/item.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class Item(models.Model):
1919
# the version of the details that the pages Replies and Reviews need: 2 with whether it
2020
# is a draft and the kind of each review
2121
DETAILS = 2
22+
# the version of reading the review threads: 1 reads all threads, comments and commits,
23+
# 0 read only the first ones; pull requests read with an older version are read again
24+
THREADS = 1
2225
repository = models.ForeignKey(Repository, models.CASCADE, related_name="items")
2326
kind = models.CharField(max_length=5, choices=[(PR, "pull request"), (ISSUE, "issue")])
2427
number = models.IntegerField()
@@ -43,6 +46,8 @@ class Item(models.Model):
4346
# the time of the last change of the pull request when its review threads were read;
4447
# they are read again when it changed since (not by the clock of this site)
4548
threads_updated_at = models.DateTimeField(null=True, blank=True)
49+
# how the review threads were read (THREADS)
50+
threads_version = models.PositiveSmallIntegerField(default=0)
4651

4752
if TYPE_CHECKING: # the reverse relation, for the type checker
4853
events: RelatedManager[Event]

‎community_insights/sync/store.py‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def without_details(repository: Repository) -> list[str]:
135135
def without_threads(repository: Repository) -> list[str]:
136136
"""The pull requests whose review threads were not read since they changed, by node ids.
137137
138-
Only those with a review by somebody: a suggestion is a review comment.
138+
Only those with a review by somebody: a suggestion is a review comment. Also those read
139+
with an older version of reading (``Item.THREADS``), which missed later pages.
139140
140141
Args:
141142
repository: The repository.
@@ -146,7 +147,11 @@ def without_threads(repository: Repository) -> list[str]:
146147
reviewed = Event.objects.filter(item__repository=repository, kind=Event.REVIEW).values("item")
147148
return list(
148149
Item.objects.filter(repository=repository, kind=Item.PR, pk__in=reviewed)
149-
.filter(Q(threads_updated_at__isnull=True) | ~Q(threads_updated_at=F("updated_at")))
150+
.filter(
151+
Q(threads_updated_at__isnull=True)
152+
| ~Q(threads_updated_at=F("updated_at"))
153+
| Q(threads_version__lt=Item.THREADS)
154+
)
150155
.exclude(node_id="")
151156
.order_by("-updated_at")
152157
.values_list("node_id", flat=True)
@@ -178,7 +183,8 @@ def save_threads(repository: Repository, nodes: list[dict | None]) -> int:
178183
Suggestion.objects.bulk_create([Suggestion(item=item, **row) for row in found])
179184
stored += len(found)
180185
item.threads_updated_at = item.updated_at
181-
item.save(update_fields=["threads_updated_at"])
186+
item.threads_version = Item.THREADS
187+
item.save(update_fields=["threads_updated_at", "threads_version"])
182188
return stored
183189

184190

‎docs/explanation/suggestions.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The pages also show why a suggestion has its status, such as *a reply names a co
3939
How the suggestions are read
4040
============================
4141

42-
The suggestions are read from GitHub with the fetch of a repository: all review threads of each pull request that got a review, all comments of each thread, and all commits of the pull request. The first request asks for 10 pull requests at a time with their first 50 threads, the first 20 comments of each thread and the first 100 commits; whatever does not fit is read in further pages of 100 until nothing is left. The authors and co-authors are read only of the commits named *Apply suggestion…*, 100 commits in a request: asking them of every commit would cost many more API points. A pull request is read again when it changed on GitHub since. Reading them needs a GitHub token, which the fetches of insight.pycal.org have; without one, the pages have no suggestions.
42+
The suggestions are read from GitHub with the fetch of a repository: all review threads of each pull request that got a review, all comments of each thread, and all commits of the pull request. The first request asks for 10 pull requests at a time with their first 50 threads, the first 20 comments of each thread and the first 100 commits; whatever does not fit is read in further pages of 100 until nothing is left. The authors and co-authors are read only of the commits named *Apply suggestion…*, 100 commits in a request: asking them of every commit would cost many more API points. A pull request is read again when it changed on GitHub since, and once more if it was read before all pages were read (``Item.THREADS``). Reading them needs a GitHub token, which the fetches of insight.pycal.org have; without one, the pages have no suggestions.
4343

4444
GitHub itself lists at most 250 commits of a pull request; a suggestion applied by a commit before those is found only if a reply names the commit.
4545

‎news/+all-threads.feature‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
All review threads, comments and commits of a pull request are read for its suggestions, no longer only the first ones; the estimate of a fetch counts these requests.
1+
All review threads, comments and commits of a pull request are read for its suggestions, no longer only the first ones; those read before are read again once with the next fetch. The estimate of a fetch counts these requests.

‎tests/fetching/test_thread_pages.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""All review threads, comments and commits are read, also beyond the first page."""
22

3+
import pytest
34
from asgiref.sync import async_to_sync
45

56
from community_insights.sync.queries import (
@@ -145,3 +146,21 @@ def test_many_commits_that_applied_suggestions():
145146
client = PagedThreadsClient([data], {f"c{n}": ["bob"] for n in range(150)}, size=100)
146147
read(client)
147148
assert client.queries.count(commit_authors_query()) == 2
149+
150+
151+
@pytest.mark.django_db
152+
def test_pull_requests_read_with_the_first_pages_only_are_read_again(user):
153+
"""Read before all pages were read (version 0): the next fetch reads them again."""
154+
from community_insights.models import Item
155+
from community_insights.sync import store
156+
from tests.pages.test_suggestions import suggestion_client
157+
158+
from ..data import read_repository
159+
from ..fakes import repo
160+
161+
repository = store.store_repository(repo("o/r", 5))
162+
read_repository(suggestion_client(), repository)
163+
assert store.without_threads(repository) == []
164+
assert set(Item.objects.filter(number=1).values_list("threads_version", flat=True)) == {1}
165+
Item.objects.update(threads_version=0)
166+
assert len(store.without_threads(repository)) == 5, "the reviewed pull requests"

‎todo.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ response times, who contributes how and when, verifiable numbers and badges.
182182
- [x] Release 0.5.0 with the suggestions
183183
- [x] The browser tests failed again while signing up on the CI: the sign-up waits for the answer of the server to the form, sends it again after a server error (SQLite busy), and names the status if it fails
184184
- [x] Can "resolved by the author" count as applied? (asked) No: resolving is a click that ends the conversation; GitHub links no commit to it. Answered; it stays unknown (docs explanation/suggestions.rst)
185-
- [x] All review threads, all comments of each thread and all commits of a pull request are read, in further pages (asked: the deployed site has tokens); the authors only of the commits named "Apply suggestion..." (sync/sources/graphql.py threads, rest_of; queries more_threads_query, more_thread_comments_query, more_pull_commits_query, commit_authors_query)
185+
- [x] All review threads, all comments of each thread and all commits of a pull request are read, in further pages (asked: the deployed site has tokens); the authors only of the commits named "Apply suggestion..." (pull requests read before are read again once: Item.THREADS, migration 0015; sync/sources/graphql.py threads, rest_of; queries more_threads_query, more_thread_comments_query, more_pull_commits_query, commit_authors_query)
186186
- [x] The badge of a pull request is "suggestions | 3/5"; ?number=1 makes it "PR #12 suggestions | 3/5", default off, a checkbox on the page of the pull request (asked); the mini badges of the tables the same
187187
- [x] The pages of suggestions filter by the state of the pull request: open, closed, merged; only open by default (asked); the page of one pull request shows it in any state
188188
- [x] Suggestions sorted by the latest first (asked): the pull request with the newest suggestion first, and newest first within one

0 commit comments

Comments
 (0)