Tag Tracking+ API efficiency note dump #1988
Replies: 3 comments 2 replies
-
|
I've been thinking about this too... my own much less detailed thought dump:
|
Beta Was this translation helpful? Give feedback.
-
I was thinking it would be annoying if you had the option to hide zero-count on. But I guess the cached count can't really be too high, just too low.
True. One thing I didn't get down is that making tabs coordinate makes the background tab case less of a big deal. We could certainly make a long delay before it kicks in. |
Beta Was this translation helpful? Give feedback.
-
|
master...marcustyphoon:XKit-Rewritten:tag-tracking-coordinate-tabs-1 Well, that was a fun test of whether I can write code in my head. Answer: ehhh, kind of. I'd forgotten a few things and there were some pretty major typos in the part I had written out. (Anyway, eh, maybe this tab coordination MVP functions. Kind of hard to tell, tbh.) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
currently, with a single tumblr tab in steady state, each tag is updated every [number of tracked tags * 30 seconds]. with n tabs, this is also true, but we do n times too many api requests. also, if a tab is inactive, we really don't need to do any api requests on it until the user focuses it again (though we must then refresh any we skipped).
to keep the same cycle but not fetch when tab is inactive: if tab is inactive when query would happen, add it to a set; when tab becomes active, clear set and interval, query everything in set with 1s cadence, then start 30s interval.
to use storage to coordinate between tabs: save unreadCounts: record<tag, count> to storage; make onStorageChanged use unreadCounts to update unreadCountElement; make unreadCountElement hidden initially. then:
although... note that different tabs could have different tracked tags if they're different accounts. I guess you would have to do...
a possibly more logical (but possibly not!) way would be doing a refresh cycle like, I dunno, "every 30 seconds, update the tracked tag that is older than 30 seconds out of date and has gone the longest without a refresh." well—not that, because then multiple tabs would increase api load and get closer to—hold on.
see, initially I had assumed something vaguely like "make sure every tag is no more than a minute out of date" was equivalent to the current behavior, but it absolutely isn't (track 100 tags and they'll be 25 minutes(!) out of date on average with current code). I quickly realized that wasn't even close to the case, but most of my thoughts about how to make n tabs behave the same as 1 tab were doing something of the sort.
of course, you could do "make sure every tag is no more than [number of tracked tags * 30 seconds] out of date" pretty easily, which would yield the same api requests per second figure as the current code. in the case where you track 100 tags, that would mean waiting 25 minutes, then firing 100 api requests one-per-few-seconds, repeat. this is certainly not the same thing as the current behavior but it's not, like... crazy? (maybe put some bounds on the interval, I dunno. 1 minute-10 minutes?)
Beta Was this translation helpful? Give feedback.
All reactions