parallelize

This commit is contained in:
Hailey
2024-06-17 19:25:38 -07:00
parent 9ccfec15e8
commit 2c59122a05
2 changed files with 30 additions and 16 deletions
-1
View File
@@ -1,5 +1,4 @@
const pkg = require('./package.json') const pkg = require('./package.json')
const {IS_TEST} = require('#/env')
const SPLASH_CONFIG = { const SPLASH_CONFIG = {
backgroundColor: '#ffffff', backgroundColor: '#ffffff',
+30 -15
View File
@@ -3,6 +3,7 @@ import {msg} from '@lingui/macro'
import {logger} from '#/logger' import {logger} from '#/logger'
import {sanitizeHandle} from 'lib/strings/handles' import {sanitizeHandle} from 'lib/strings/handles'
import {enforceLen} from 'lib/strings/helpers'
export const createStarterPackList = async ({ export const createStarterPackList = async ({
name, name,
@@ -54,28 +55,42 @@ export async function generateStarterpack({
agent: BskyAgent agent: BskyAgent
}): Promise<string | 'NOT_ENOUGH_FOLLOWERS' | 'ERROR'> { }): Promise<string | 'NOT_ENOUGH_FOLLOWERS' | 'ERROR'> {
try { try {
const profileRes = await agent.app.bsky.actor.getProfile({ let profile: AppBskyActorDefs.ProfileViewBasic | undefined
actor: agent.session!.did, let profiles: AppBskyActorDefs.ProfileViewBasic[] | undefined
})
const profile = profileRes.data
const defaultName = `${ await Promise.all([
profile.displayName || `@${sanitizeHandle(profile.handle)}` (async () => {
}${msg`'s Starter Pack`.message!}` profile = (
await agent.app.bsky.actor.getProfile({
actor: agent.session!.did,
})
).data
})(),
(async () => {
profiles = (
await agent.app.bsky.actor.searchActors({
q: encodeURIComponent('*'),
limit: 49,
})
).data.actors.filter(p => p.viewer?.following)
})(),
])
const profilesRes = await agent.app.bsky.actor.searchActors({ if (!profile || !profiles) {
q: encodeURIComponent('*'), return 'ERROR'
limit: 49, }
})
const profiles = [
profile,
...profilesRes.data.actors.filter(p => p.viewer?.following),
]
profiles = [profile, ...profiles]
if (profiles.length < 8) { if (profiles.length < 8) {
return 'NOT_ENOUGH_FOLLOWERS' return 'NOT_ENOUGH_FOLLOWERS'
} }
const defaultName = `${enforceLen(
profile.displayName || `@${sanitizeHandle(profile.handle)}`,
25,
true,
)}${msg`'s Starter Pack`.message!}`
const list = await createStarterPackList({ const list = await createStarterPackList({
name: defaultName ?? '', name: defaultName ?? '',
profiles, profiles,