fix: don't refetch Threads avatars whose signed URL changed (v2.13.0)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
55ce6a1fdd
commit
d400e4d838
3 files changed
+34
-2
No files matched your search
@@ -27,14 +27,15 @@ Implements ADR-073.
|
|||||||
|
|
||||||
## Verification
|
## Verification
|
||||||
|
|
||||||
- `tests/test_backfeed.py` (21 tests): schedule; text/facet HTML; storing,
|
- `tests/test_backfeed.py` (22 tests): schedule; text/facet HTML; storing,
|
||||||
updating and moderation kept; pruning only on complete harvests and
|
updating and moderation kept; pruning only on complete harvests and
|
||||||
restoring; opt-outs; tombstones; backfill and its pacing; likes/reposts
|
restoring; opt-outs; tombstones; backfill and its pacing; likes/reposts
|
||||||
and drafts skipped; refused credentials; backoff; note page (via label,
|
and drafts skipped; refused credentials; backoff; note page (via label,
|
||||||
quotes, Threads counts, local avatars); avatar save/serve/cleanup;
|
quotes, Threads counts, local avatars); avatar save/serve/cleanup;
|
||||||
webmention can't overwrite a backfed row; the three clients against fake
|
webmention can't overwrite a backfed row; the three clients against fake
|
||||||
APIs; migration 020 on a pre-020 database keeps rows and foreign keys;
|
APIs; migration 020 on a pre-020 database keeps rows and foreign keys;
|
||||||
the admin Backfeed panel, backfill and Check now.
|
the admin Backfeed panel, backfill and Check now; Threads avatar URLs
|
||||||
|
(signed, changing per request) aren't refetched while a copy exists.
|
||||||
- Tests for the touched areas (webmentions, syndication, microformats,
|
- Tests for the touched areas (webmentions, syndication, microformats,
|
||||||
migrations, templates, routes): all pass. The full suite runs in CI.
|
migrations, templates, routes): all pass. The full suite runs in CI.
|
||||||
- `test_microformats_v280` expects response authors' `u-photo`: kept via
|
- `test_microformats_v280` expects response authors' `u-photo`: kept via
|
||||||
|
|||||||
@@ -256,9 +256,18 @@ def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest) -> N
|
|||||||
keep = [r for r in harvest.responses if not _opted_out(r)]
|
keep = [r for r in harvest.responses if not _opted_out(r)]
|
||||||
dropped = [r.source_url for r in harvest.responses if _opted_out(r)]
|
dropped = [r.source_url for r in harvest.responses if _opted_out(r)]
|
||||||
|
|
||||||
|
from starpunk.avatars import cached_name
|
||||||
|
|
||||||
before = _display_state(db, note_id)
|
before = _display_state(db, note_id)
|
||||||
for r in keep:
|
for r in keep:
|
||||||
snippet = _snippet(r.content_html) if r.content_html else None
|
snippet = _snippet(r.content_html) if r.content_html else None
|
||||||
|
# Threads avatar URLs are signed and change on every request: keep
|
||||||
|
# the stored URL while its saved copy exists, so it isn't refetched
|
||||||
|
old = db.execute("SELECT author_photo FROM webmentions WHERE source_url = ? AND target_url = ?",
|
||||||
|
(r.source_url, target_url)).fetchone()
|
||||||
|
if old and old["author_photo"] and origin == "threads" \
|
||||||
|
and cached_name(current_app.config["DATA_PATH"], old["author_photo"]):
|
||||||
|
r.author_photo = old["author_photo"]
|
||||||
db.execute(
|
db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO webmentions (
|
INSERT INTO webmentions (
|
||||||
|
|||||||
@@ -540,3 +540,25 @@ def test_admin_backfill_and_check_now(app, client):
|
|||||||
|
|
||||||
backfeed.denied["gotosocial"] = "Needs a GoToSocial token with read:statuses"
|
backfeed.denied["gotosocial"] = "Needs a GoToSocial token with read:statuses"
|
||||||
assert "Needs a GoToSocial token" in browser.get("/admin/webmentions?origin=gotosocial").get_data(as_text=True)
|
assert "Needs a GoToSocial token" in browser.get("/admin/webmentions?origin=gotosocial").get_data(as_text=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_threads_avatar_kept_while_its_copy_exists(app, client, web):
|
||||||
|
note, _ = crossposted(app)
|
||||||
|
with app.app_context():
|
||||||
|
get_db(app).execute("UPDATE syndications SET target = 'threads'")
|
||||||
|
get_db(app).commit()
|
||||||
|
syndication._client_cache["threads"] = client
|
||||||
|
app.config["THREADS_ACCESS_TOKEN"] = "token"
|
||||||
|
web.files["https://cdn.example/p.jpg?sig=1"] = png()
|
||||||
|
first = reply(1)
|
||||||
|
first.author_photo = "https://cdn.example/p.jpg?sig=1"
|
||||||
|
client.harvest = Harvest([first])
|
||||||
|
run(app)
|
||||||
|
with app.app_context():
|
||||||
|
get_db(app).execute("UPDATE syndications SET backfeed_next_at = datetime('now')")
|
||||||
|
get_db(app).commit()
|
||||||
|
again = reply(1)
|
||||||
|
again.author_photo = "https://cdn.example/p.jpg?sig=2" # not fetchable: would be a refetch
|
||||||
|
client.harvest = Harvest([again])
|
||||||
|
run(app)
|
||||||
|
assert rows(app, note.id)[0]["author_photo"] == "https://cdn.example/p.jpg?sig=1"
|
||||||
Reference in new issue
Block a user