Reduce calls to getFeedGenerator and getFeed (#2166)

* Reduce calls to getFeedGenerator by the mergefeed

* Dont run end-of-follows mergefeed requests until actually at the end of the feed

* build AWS container

---------

Co-authored-by: Jake Gold <jake@blueskyweb.xyz>
zio/stable
Paul Frazee 2023-12-11 12:58:34 -08:00 committed by GitHub
parent 3d229b5fd6
commit b82c5177b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 27 deletions

View File

@ -3,7 +3,7 @@ on:
push: push:
branches: branches:
- main - main
- jake/bskyweb-additions - traffic-reduction
env: env:
REGISTRY: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_REGISTRY }} REGISTRY: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_REGISTRY }}
USERNAME: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_USERNAME }} USERNAME: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_USERNAME }}

View File

@ -62,7 +62,7 @@ export class MergeFeedAPI implements FeedAPI {
// always keep following topped up // always keep following topped up
if (this.following.numReady < limit) { if (this.following.numReady < limit) {
promises.push(this.following.fetchNext(60)) await this.following.fetchNext(60)
} }
// pick the next feeds to sample from // pick the next feeds to sample from
@ -73,9 +73,13 @@ export class MergeFeedAPI implements FeedAPI {
} }
// top up the feeds // top up the feeds
for (const feed of feeds) { const outOfFollows =
if (feed.numReady < 5) { !this.following.hasMore && this.following.numReady < limit
promises.push(feed.fetchNext(10)) if (this.params.mergeFeedEnabled || outOfFollows) {
for (const feed of feeds) {
if (feed.numReady < 5) {
promises.push(feed.fetchNext(10))
}
} }
} }
@ -216,22 +220,10 @@ class MergeFeedSource_Custom extends MergeFeedSource {
super(feedTuners) super(feedTuners)
this.sourceInfo = { this.sourceInfo = {
$type: 'reasonFeedSource', $type: 'reasonFeedSource',
displayName: feedUri.split('/').pop() || '', uri: feedUri,
uri: feedUriToHref(feedUri), href: feedUriToHref(feedUri),
} }
this.minDate = new Date(Date.now() - POST_AGE_CUTOFF) this.minDate = new Date(Date.now() - POST_AGE_CUTOFF)
getAgent()
.app.bsky.feed.getFeedGenerator({
feed: feedUri,
})
.then(
res => {
if (this.sourceInfo) {
this.sourceInfo.displayName = res.data.view.displayName
}
},
_err => {},
)
} }
protected async _getFeed( protected async _getFeed(

View File

@ -19,7 +19,7 @@ export interface FeedAPI {
export interface ReasonFeedSource { export interface ReasonFeedSource {
$type: 'reasonFeedSource' $type: 'reasonFeedSource'
uri: string uri: string
displayName: string href: string
} }
export function isReasonFeedSource(v: unknown): v is ReasonFeedSource { export function isReasonFeedSource(v: unknown): v is ReasonFeedSource {

View File

@ -33,6 +33,7 @@ import {MAX_POST_LINES} from 'lib/constants'
import {countLines} from 'lib/strings/helpers' import {countLines} from 'lib/strings/helpers'
import {useComposerControls} from '#/state/shell/composer' import {useComposerControls} from '#/state/shell/composer'
import {Shadow, usePostShadow, POST_TOMBSTONE} from '#/state/cache/post-shadow' import {Shadow, usePostShadow, POST_TOMBSTONE} from '#/state/cache/post-shadow'
import {FeedNameText} from '../util/FeedInfoText'
export function FeedItem({ export function FeedItem({
post, post,
@ -177,22 +178,20 @@ let FeedItemInner = ({
<View style={{paddingTop: 12, flexShrink: 1}}> <View style={{paddingTop: 12, flexShrink: 1}}>
{isReasonFeedSource(reason) ? ( {isReasonFeedSource(reason) ? (
<Link <Link href={reason.href}>
title={sanitizeDisplayName(reason.displayName)}
href={reason.uri}>
<Text <Text
type="sm-bold" type="sm-bold"
style={pal.textLight} style={pal.textLight}
lineHeight={1.2} lineHeight={1.2}
numberOfLines={1}> numberOfLines={1}>
From{' '} From{' '}
<TextLinkOnWebOnly <FeedNameText
type="sm-bold" type="sm-bold"
style={pal.textLight} uri={reason.uri}
href={reason.href}
lineHeight={1.2} lineHeight={1.2}
numberOfLines={1} numberOfLines={1}
text={sanitizeDisplayName(reason.displayName)} style={pal.textLight}
href={reason.uri}
/> />
</Text> </Text>
</Link> </Link>

View File

@ -0,0 +1,54 @@
import React from 'react'
import {StyleProp, StyleSheet, TextStyle} from 'react-native'
import {TextLinkOnWebOnly} from './Link'
import {LoadingPlaceholder} from './LoadingPlaceholder'
import {TypographyVariant} from 'lib/ThemeContext'
import {sanitizeDisplayName} from 'lib/strings/display-names'
import {useFeedSourceInfoQuery} from '#/state/queries/feed'
export function FeedNameText({
type = 'md',
uri,
href,
lineHeight,
numberOfLines,
style,
}: {
type?: TypographyVariant
uri: string
href: string
lineHeight?: number
numberOfLines?: number
style?: StyleProp<TextStyle>
}) {
const {data, isError} = useFeedSourceInfoQuery({uri})
let inner
if (data?.displayName || isError) {
const displayName = data?.displayName || uri.split('/').pop() || ''
inner = (
<TextLinkOnWebOnly
type={type}
style={style}
lineHeight={lineHeight}
numberOfLines={numberOfLines}
href={href}
text={sanitizeDisplayName(displayName)}
/>
)
} else {
inner = (
<LoadingPlaceholder
width={80}
height={8}
style={styles.loadingPlaceholder}
/>
)
}
return inner
}
const styles = StyleSheet.create({
loadingPlaceholder: {position: 'relative', top: 1, left: 2},
})