snarfed / bridgy

📣 Connects your web site to social media. Likes, retweets, mentions, cross-posting, and more...
https://brid.gy
Creative Commons Zero v1.0 Universal
707 stars 52 forks source link

Bluesky: look into optimizing API calls #1597

Closed snarfed closed 9 months ago

snarfed commented 10 months ago

Wow! Bluesky only has 26 users, ~1% of all active users that we poll, but it's already the solid majority of all outbound HTTP requests! We should eventually look into optimizing those. First step would be to get the like/repost cache working, based on counts, and only fetch those when the count increases...but I'm not sure the Bluesky API gives us those counts? cc @JoelOtter

image
JoelOtter commented 9 months ago

No it does! I just was unaware of how the caching works to begin with. Happy to have a look :)

JoelOtter commented 9 months ago

Actually it looks like Bluesky is already using the cache for replies, reposts and likes?

snarfed commented 9 months ago

You're right, granary reads and writes it, and it gets passed through from the Bluesky.last_activities_cache_json datastore property here:

https://github.com/snarfed/bridgy/blob/8c809d251d4ef57c8f8ad69aa3472dc22155fc64/tasks.py#L132-L144

...and yet it's not working. Hmm. 😐 Maybe first check if any of the Bluesky entities in the datastore actually have anything stored in that property? https://console.cloud.google.com/datastore/entities/query?project=brid-gy

JoelOtter commented 9 months ago

OH

JoelOtter commented 9 months ago

This might actually be (part of?) the cause of #1592

snarfed commented 9 months ago

Huh, you're probably right! Great catch.

snarfed commented 9 months ago

Looks like it worked! When there's nothing new, a Bluesky poll now only does a single API call, down from as many as 91 before. 😆

image
snarfed commented 9 months ago

(@JoelOtter you should hopefully be able to see the dashboard too, feel free to poke around: https://console.cloud.google.com/monitoring/dashboards/builder/0e3a0a00-ce6f-4f3e-a907-4ddabd3288a6;duration=PT24H?project=brid-gy&dashboardBuilderState=%257B%2522editModeEnabled%2522%3Afalse%257D )