Skip to content

Feed · Modules

15 modules · 52 exports · 5 repositories · 3 e2e tests · 1 route

Who imports who · hover a node
Depends onFeed modulesUsed byArticles.serverarticlesAvailabilityavailabilitySchedules.serveravailab…ScheduleWeekavailabilityShowcaseTournaments.serverLeaderboardlobbiesSeasonsmmrSeriestournament-organizat…FeedCache.server3 expor…FeedComments.server2 ex…FeedEvents6 exportsFeedIndexer.server1 exp…FeedItemIds2 exportsFeedItems.server7 expor…FeedLfgMatch5 exportsFeedPage.server3 exportsFeedRanking5 exportsFeedRotations3 exportsFeedSchedule5 exportsFeedScrimMatch5 exportsFeedSeasonGoal2 exportsFeedShare.server2 expor…FeedWeaponTrends1 exportOther4 filesLoaders2 filesRoutines1 fileActions1 fileComponents7 filesRoutes1 file

FeedCache

serverapp/features/feed/core/FeedCache.server.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module1 other

Functions & values

function

cached

:16

The value of the key, computed at most once per ttlMs. Past that the stale value is still returned for up to staleMs while a fresh one is computed in the background.

export function cached<T>({
	key,
	ttlMs,
	staleMs = ttlMs * 10,
	getFreshValue,
}: {
	key: string;
	ttlMs: number;
	staleMs?: number;
	getFreshValue: () => Promise<T>;
})
function

clear

:37

Empties every feed cache.

export function clear()
function

cachedByIds

:43

Rows by id, the ones not cached within ttlMs fetched with one call of fetch.

export async function cachedByIds<T>({
	prefix,
	ids,
	ttlMs,
	fetch,
	idOf,
}: {
	prefix: string;
	ids: number[];
	ttlMs: number;
	fetch: (ids: number[]) => Promise<T[]>;
	idOf: (row: T) => number;
}): Promise<Map<number, T>>

FeedComments

serverapp/features/feed/core/FeedComments.server.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 loader1 module

Functions & values

function

forItem

:12

The comments of the post, on the test page preceded by mocked ones written by the viewer's friends.

export async function forItem({
	item,
	mode,
	friends,
	now,
}: {
	item: FeedItem;
	mode: FeedMode;
	friends: ChatMessageAuthor[];
	now: number;
}): Promise<ChatMessageWithAuthor[]>
Loaders/feed/:id
function

countByItem

:49

How many comments each post has, by post id, as forItem returns them.

export async function countByItem({
	items,
	mode,
	hasFriends,
}: {
	items: FeedItem[];
	mode: FeedMode;
	hasFriends: boolean;
})

FeedEvents

app/features/feed/core/FeedEvents.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
2 modules

Types

interface

SqPlay

no JSDoc:29
export interface SqPlay {
	source: "SQ";
	at: number;
	matchId: number;
	season: number;
	ordinal: number;
	/** Before this set, also counting tournaments of the season. `null` when this set was the first. */
	previousOrdinal: number | null;
	isWin: boolean;
	ownTier: FeedTier | null;
	opponentTier: FeedTier | null;
}
interface

TournamentPlay

no JSDoc:42
export interface TournamentPlay {
	source: "TOURNAMENT";
	at: number;
	tournamentId: number;
	tournamentTeamId: number;
	placement: number;
	participantCount: number;
	setWins: number;
	setLosses: number;
	name: string;
	organizationId: number | null;
}
type

DerivedEvent

no JSDoc:57
export type DerivedEvent = {
	[T in FeedEventType]: { type: T; at: number; data: FeedEventDataByType[T] };
}[FeedEventType];
interface

SeasonTiers

no JSDoc:61
export interface SeasonTiers {
	intervals: SkillTierInterval[];
	/** The user's tier the season before, promotions below it aren't notable */
	previousSeasonTier: FeedTier | null;
}

Functions & values

function

derive

:72

The feed events of one user's whole play history (SendouQ sets and tournaments) within each type's retention. Of every type but tournament results only the latest is kept, the only one a feed item shows. The history must be complete since comebacks, first times, milestones and streaks look at the plays before.

export function derive({
	plays,
	now,
	tiersOfSeason,
}: {
	plays: Play[];
	now: number;
	tiersOfSeason: (season: number) => SeasonTiers | undefined;
}): DerivedEvent[]
Unit tests (12)
function

tierRank

:219

Position on the ladder where each plus tier is its own step, e.g. Diamond+ is one above Diamond.

export function tierRank(tier: { name: string; isPlus: boolean })

Not shown, only used by tests: Play

FeedIndexer

serverapp/features/feed/core/FeedIndexer.server.ts

No overview comment at the top of the file.

Imports
FeedEvents
Used by
1 routine1 other

Functions & values

function

run

:22

Re-derives the feed events of everyone who finished a SendouQ set or a tournament since the last run and drops the events past retention. The first run indexes everyone who played within retention. Yields to the event loop between users so a big backlog doesn't stall requests.

export async function run()

FeedItemIds

app/features/feed/core/FeedItemIds.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 action1 module1 other

Functions & values

function

make

:9

Id of a feed post: its type, when it happened and a hash of who it's about. Comments and reactions are attached to it, so it stays the same for as long as the post shows the same thing.

export function make({
	type,
	at,
	actorKey,
}: {
	type: FeedItemType;
	at: number;
	actorKey: string;
})
Unit tests (2)
function

typeOf

:22

The post type of the id, null when it isn't a post id.

export function typeOf(id: string): FeedItemType | null
Unit tests (2)

FeedItems

serverapp/features/feed/core/FeedItems.server.ts

No overview comment at the top of the file.

Imports
Articles.serverAvailabilitySchedules.serverScheduleWeekShowcaseTournaments.serverLeaderboardSeasonsSeriesFeedCache.serverFeedEventsFeedItemIdsFeedLfgMatchFeedRankingFeedRotationsFeedScheduleFeedScrimMatchFeedSeasonGoalFeedWeaponTrends
Used by
1 loader2 modules7 components

Types

type

FeedMode

:143

REAL is the feed as it is now, TEST the dev test page: "now" follows the latest SendouQ match and items fall back to placeholders and rows of anyone

export type FeedMode = "REAL" | "TEST";
interface

FeedContext

no JSDoc:145
export interface FeedContext {
	mode: FeedMode;
	viewerId: number;
	friendIds: number[];
	friendIdSet: Set<number>;
	/** Users sharing a current team with the viewer who aren't their friends */
	teammateIds: number[];
	teammateIdSet: Set<number>;
	/** Weapons of the viewer's weapon pool, see `RankableItem.weaponSplIds` */
	weaponPool: MainWeaponId[];
	/** Database timestamp everything is relative to */
	now: number;
	season: number | null;
	previousSeason: number | null;
	/** Queries several items of the same request share, by key */
	memo: Map<string, Promise<unknown>>;
}
Only used inside the module
type

FeedItem

no JSDoc:260
export type FeedItem = {
	[T in FeedItemType]: {
		/** See `FeedItemIds` */
		id: string;
		type: T;
		at: number;
		actorKey: string;
		relation: FeedRelation | null;
		weight: number;
		weaponSplIds: MainWeaponId[];
		data: FeedItemData<T>;
	};
}[FeedItemType];

Functions & values

function

contextFor

:275

The feed context of the viewer. In TEST mode "now" is shortly after the latest SendouQ match.

export async function contextFor({
	viewerId,
	mode,
}: {
	viewerId: number;
	mode: FeedMode;
}): Promise<FeedContext>
function

findById

:339

The post with the id as the viewer sees it now, null once their feed no longer has it.

export async function findById({
	id,
	viewerId,
}: {
	id: string;
	viewerId: number;
}): Promise<{ item: FeedItem; ctx: FeedContext } | null>
Loaders/feed/:id
function

buildAll

:364

Builds the items of every type that has matching rows, as seen by the viewer of the context. A builder that throws is logged and skipped so one broken query doesn't take the page down.

export async function buildAll(ctx: FeedContext): Promise<FeedItem[]>
function

allRotations

:3555

The Splatoon 3 rotations, cached for a minute.

export function allRotations()

FeedLfgMatch

app/features/feed/core/FeedLfgMatch.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module1 other

Functions & values

function

match

:23

How well another LFG post fits the viewer's own, 0–1: timezone closeness weighted by FEED_LFG_TIMEZONE_WEIGHT, skill closeness by the rest. null when it doesn't fit well enough to show (below FEED_LFG_MIN_MATCH) or both posts list languages but none in common.

export function match(
	own: LfgPostProfile,
	other: LfgPostProfile,
): number | null
Unit tests (2)
function

levelMatch

:48

How well a tournament team's level fits the viewer's, 0–1: the skill part of match alone, since the tournament fixes the time. null below FEED_LFG_MIN_MATCH.

export function levelMatch(
	ownTierRank: number | null,
	otherTierRank: number | null,
): number | null
Unit tests (1)
function

medianTierRank

:62

Median of the tier ranks, how a team post's skill is measured. null when there are none.

export function medianTierRank(tierRanks: number[])
Unit tests (1)
function

timezoneScore

:74

Timezone part of match, 0–1 from the hours between the posts' timezones

export function timezoneScore(hours: number)
function

skillScore

:83

Skill part of match, 0–1 from the tier steps between the posts, null when either has no accurate tier

export function skillScore(tierSteps: number | null)

Not shown, only used by tests: LfgPostProfile

FeedPage

serverapp/features/feed/core/FeedPage.server.ts

No overview comment at the top of the file.

Imports
FeedComments.serverFeedItems.serverFeedRankingFeedShare.server
Used by
1 loader1 route2 components

Types

type

FeedPageData

no JSDoc:14
export type FeedPageData = Awaited<ReturnType<typeof load>>;
Routes/
Componentsfeed/Feed.tsx
interface

FeedItemInteractions

no JSDoc:74
export interface FeedItemInteractions {
	commentCount: number;
	reactionCount: number;
	isReacted: boolean;
	shareToken: string;
}

Functions & values

function

load

:17

Everything a feed page shows: the viewer's posts in order with their comment and reaction counts as userId sees them.

export async function load({
	viewerId,
	userId,
	mode,
	isScoreShown,
}: {
	viewerId: number;
	/** The logged in user, differs from `viewerId` when a dev views someone else's feed */
	userId: number;
	mode: FeedItems.FeedMode;
	/** Whether each post's ranking score breakdown is included */
	isScoreShown: boolean;
})
Loaders/

FeedRanking

app/features/feed/core/FeedRanking.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
2 modules2 components

Types

interface

RankableItem

no JSDoc:20
export interface RankableItem {
	type: FeedItemType;
	/** Database timestamp (seconds) of when the item happened */
	at: number;
	/** Who the item is about, used to stop one person taking over the feed */
	actorKey: string;
	/** How the viewer knows who the item is about, `null` when it isn't about someone they know */
	relation: FeedRelation | null;
	/** How strong the item is among those of its type, 0–1, 1 when left out */
	weight?: number;
	/** Weapons the item is about, matched against the viewer's weapon pool */
	weaponSplIds?: MainWeaponId[];
}
Only used inside the module
interface

ScoreBreakdown

no JSDoc:34
export interface ScoreBreakdown {
	base: number;
	weight: number;
	affinity: number;
	weaponAffinity: number;
	recency: number;
	ageHours: number;
	diversity: number;
	total: number;
}

Functions & values

function

score

:50

Score of an item before the diversity pass: base score of its type × the item's weight × affinity × weapon affinity × exponential recency decay by the type's half-life. Affinity is that of the item's relation, or without one the widest audience of its type.

export function score(
	item: Pick<
		RankableItem,
		"type" | "at" | "relation" | "weight" | "weaponSplIds"
	>,
	now: number,
	weaponPool: MainWeaponId[] = [],
): Omit<ScoreBreakdown, "diversity">
Unit tests (6)
function

isStale

:83

Whether the item is too old to show, FEED_MAX_AGE_HALF_LIVES half-lives of its type. Pinned items never are.

export function isStale(item: Pick<RankableItem, "type" | "at">, now: number)
Unit tests (1)
function

rank

:97

Orders items by score with a greedy diversity pass: each pick is penalized if its category appeared in the previous two picks or its actor in the previous four, and once more for each earlier pick of its type.

export function rank<T extends RankableItem>(
	items: T[],
	now: number,
	weaponPool: MainWeaponId[] = [],
): Array<T & { score: ScoreBreakdown }>
Unit tests (3)

FeedRotations

app/features/feed/core/FeedRotations.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module

Functions & values

function

usualPlayHours

:12

Hours of the week (UTC) the user usually plays: ones with matches on at least FEED_ROTATION_MIN_WEEKS different weeks.

export function usualPlayHours(matchTimes: number[]): Set<number>
Unit tests (2)
function

isDuringUsualHours

:30

Whether any hour of the rotation is a usual play hour, give or take an hour (daylight saving, start time jitter).

export function isDuringUsualHours(
	rotation: { startsAt: number; endsAt: number },
	usualHours: Set<number>,
)
Unit tests (1)
function

matchingStageIds

:47

The rotation's stages that are in the user's map pool for its mode, none if the mode is avoided.

export function matchingStageIds(
	rotation: { mode: ModeShort; stageIds: readonly StageId[] },
	preferences: UserMapModePreferences | null,
): StageId[]
Unit tests (1)

FeedSchedule

app/features/feed/core/FeedSchedule.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module

Functions & values

const

WEEKDAY

no JSDoc:5
export const WEEKDAY = {
	SUNDAY: 0,
	MONDAY: 1,
	WEDNESDAY: 3,
	FRIDAY: 5,
} as const;
function

latestWeekly

:13

The latest moment at or before now that is the given UTC weekday & hour.

export function latestWeekly(
	now: Date,
	{
		weekday,
		hour = FEED_SCHEDULED_POST_HOUR_UTC,
	}: { weekday: number; hour?: number },
)
Unit tests (1)
function

showcaseWindow

:39

The tournament showcase post live at now: Monday morning's covers the weekdays until Friday morning, Friday morning's the weekend until Monday morning.

export function showcaseWindow(now: Date)
Unit tests (2)
function

latestAnniversary

:59

The latest anniversary of createdAt at or before now, null before the first one.

export function latestAnniversary(createdAt: Date, now: Date)
Unit tests (1)
function

reachedMilestone

:74

The largest milestone (1, 2 or 5 times a power of ten, at least min) that count has reached.

export function reachedMilestone(count: number, min: number)
Unit tests (1)

FeedScrimMatch

app/features/feed/core/FeedScrimMatch.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module1 component

Types

type

ScrimPostReason

no JSDoc:17
export type ScrimPostReason = (typeof SCRIM_POST_REASONS)[number];

Functions & values

const

SCRIM_POST_REASONS

:10

Why a scrim post is shown, most relevant first

export const SCRIM_POST_REASONS = [
	"REQUESTED",
	"USUAL_OPPONENT",
	"ASSOCIATION",
	"FIT",
] as const;
function

teamProfile

:41

The scrimming profile of a team from its accepted scrims and its members' serialized LUTI divs.

export function teamProfile({
	scrims,
	memberDivs,
}: {
	scrims: Array<{ opponentTeamId: number | null; startsAt: number }>;
	memberDivs: number[];
}): ScrimTeamProfile
Unit tests (3)
function

startHours

:65

UTC hours of the day a post starting at startsAt (and flexible until rangeEndsAt) can start at.

export function startHours({
	startsAt,
	rangeEndsAt,
}: {
	startsAt: number;
	rangeEndsAt: number | null;
})
Unit tests (1)
function

reasonOf

:84

Why a scrim post is shown to a member of teams with the profiles, null when it isn't. Fit needs a usual scrim hour and a div within FEED_SCRIM_FIT_MAX_DIV_GAP of the post's range.

export function reasonOf(
	profiles: ScrimTeamProfile[],
	post: ScrimPostCandidate,
): ScrimPostReason | null
Unit tests (4)

Not shown, only used by tests: ScrimTeamProfile, ScrimPostCandidate

FeedSeasonGoal

app/features/feed/core/FeedSeasonGoal.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module

Types

type

SeasonGoal

no JSDoc:6
export type SeasonGoal =
	| { type: "GET_RANKED"; setsShort: number }
	| { type: "NEXT_TIER"; tier: FeedTier; spShort: number };
Only used inside the module

Functions & values

function

seasonEndGoal

:14

What a player can still reach before the season ends: the sets they're short of getting ranked or, once ranked, the next tier when it's at most FEED_SEASON_ENDING_MAX_SP_SHORT away. null when neither applies.

export function seasonEndGoal({
	matchesCount,
	ordinal,
	intervals,
}: {
	matchesCount: number;
	ordinal: number;
	/** Tiers of the season, highest first, see `SkillTierInterval` */
	intervals: Array<FeedTier & { neededOrdinal?: number }>;
}): SeasonGoal | null
Unit tests (1)

FeedShare

serverapp/features/feed/core/FeedShare.server.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 loader1 module

Functions & values

function

token

:6

Signs a share link of the post, letting anyone who opens it see the post as the sharer does.

export function token({
	itemId,
	sharerId,
}: {
	itemId: string;
	sharerId: number;
})
function

isValid

:20

Whether the token was made by token for the post and sharer.

export function isValid({
	itemId,
	sharerId,
	token: given,
}: {
	itemId: string;
	sharerId: number;
	token: string;
})
Unit tests (2)
Loaders/feed/:id

FeedWeaponTrends

app/features/feed/core/FeedWeaponTrends.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module

Functions & values

function

risersAndFallers

:32

Weapons whose share of play rose and fell the most from last week to this week. Every player's weapon mix counts once, weighted from 1 (lowest ranked or unranked) to TOP_PLAYER_WEIGHT (highest ranked) by their ordinal among the week's players. null when either week has too few players or there is no clear riser and faller.

export function risersAndFallers({
	thisWeek,
	lastWeek,
	ordinals,
}: {
	thisWeek: WeaponPicks[];
	lastWeek: WeaponPicks[];
	/** Skill ordinal by user id */
	ordinals: Map<number, number>;
})
Unit tests (5)

Not shown, only used by tests: WeaponPicks