Fix relay selections
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
intersection, first, switcher, throttleWithValue, clamp, last, splitAt, identity, sortBy, uniq, shuffle,
|
intersection, first, switcher, throttleWithValue, clamp, last, splitAt, identity, sortBy, uniq, shuffle,
|
||||||
pushToMapKey, now, assoc, ctx,
|
pushToMapKey, now, assoc, ctx, sample,
|
||||||
} from '@welshman/lib'
|
} from '@welshman/lib'
|
||||||
import {
|
import {
|
||||||
Tags, getFilterId, unionFilters, isShareableRelayUrl, isCommunityAddress, isGroupAddress, isContextAddress,
|
Tags, getFilterId, unionFilters, isShareableRelayUrl, isCommunityAddress, isGroupAddress, isContextAddress,
|
||||||
@@ -527,7 +527,7 @@ export const getFilterSelectionsForContext = (state: FilterSelectionRuleState) =
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getFilterSelectionsForWraps = (state: FilterSelectionRuleState) => {
|
export const getFilterSelectionsForWraps = (state: FilterSelectionRuleState) => {
|
||||||
if (state.filter.kinds?.includes(WRAP) || !state.filter.authors) return false
|
if (!state.filter.kinds?.includes(WRAP) || state.filter.authors) return false
|
||||||
|
|
||||||
const id = getFilterId({...state.filter, kinds: [WRAP]})
|
const id = getFilterId({...state.filter, kinds: [WRAP]})
|
||||||
const scenario = ctx.app.router.InboxRelays().update(assoc('value', id))
|
const scenario = ctx.app.router.InboxRelays().update(assoc('value', id))
|
||||||
@@ -553,10 +553,11 @@ export const getFilterSelectionsForIndexedKinds = (state: FilterSelectionRuleSta
|
|||||||
|
|
||||||
export const getFilterSelectionsForAuthors = (state: FilterSelectionRuleState) => {
|
export const getFilterSelectionsForAuthors = (state: FilterSelectionRuleState) => {
|
||||||
// If we have a ton of authors, just use our indexers
|
// If we have a ton of authors, just use our indexers
|
||||||
if (!state.filter.authors || state.filter.authors.length > 30) return false
|
if (!state.filter.authors) return false
|
||||||
|
|
||||||
const id = getFilterId(state.filter)
|
const id = getFilterId(state.filter)
|
||||||
const scenario = ctx.app.router.FromPubkeys(state.filter.authors!).update(assoc('value', id))
|
const pubkeys = sample(50, state.filter.authors!)
|
||||||
|
const scenario = ctx.app.router.FromPubkeys(pubkeys).update(assoc('value', id))
|
||||||
|
|
||||||
state.selections.push(makeFilterSelection(id, state.filter, scenario))
|
state.selections.push(makeFilterSelection(id, state.filter, scenario))
|
||||||
|
|
||||||
|
|||||||
@@ -282,6 +282,8 @@ export const choice = <T>(xs: T[]): T => xs[Math.floor(xs.length * Math.random()
|
|||||||
|
|
||||||
export const shuffle = <T>(xs: Iterable<T>): T[] => Array.from(xs).sort(() => Math.random() > 0.5 ? 1 : -1)
|
export const shuffle = <T>(xs: Iterable<T>): T[] => Array.from(xs).sort(() => Math.random() > 0.5 ? 1 : -1)
|
||||||
|
|
||||||
|
export const sample = <T>(n: number, xs: T[]) => shuffle(xs).slice(0, n)
|
||||||
|
|
||||||
export const isIterable = (x: any) => Symbol.iterator in Object(x)
|
export const isIterable = (x: any) => Symbol.iterator in Object(x)
|
||||||
|
|
||||||
export const toIterable = (x: any) => isIterable(x) ? x : [x]
|
export const toIterable = (x: any) => isIterable(x) ? x : [x]
|
||||||
@@ -377,17 +379,6 @@ export const indexBy = <T, K>(f: (x: T) => K, xs: T[]) => {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sample = <T>(n: number, xs: T[]) => {
|
|
||||||
const result: T[] = []
|
|
||||||
const limit = Math.min(n, xs.length)
|
|
||||||
|
|
||||||
for (let i = 0; i < limit; i++) {
|
|
||||||
result.push(xs.splice(Math.floor(xs.length * Math.random()), 1)[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export const initArray = <T>(n: number, f: () => T) => {
|
export const initArray = <T>(n: number, f: () => T) => {
|
||||||
const result = []
|
const result = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user