<commit_before>import { AlgoliaClient } from 'algoliasearch'
import { FirebaseApp } from '../firebase'

import { firestoreRawCollection, WithId } from '../firestore/collection'
import { SpeakerData, UserData } from '../firestore/data'
import { SpeakerRecord } from './records'

export const indexSpeakers = (firebaseApp: FirebaseApp, algolia: AlgoliaClient, indexPrefix: string): Promise<void> => {
    const speakersIndex = algolia.initIndex(`${indexPrefix}_speakers`)

    const collection = firestoreCollection(firebaseApp)

    const speakersPromise = rawCollection<SpeakerData>('speakers')
    const userProfilesPromise = rawCollection<UserData>('user_profiles')

    return Promise.all([speakersPromise, userProfilesPromise])
        .then(([speakers, userProfiles]) => toSpeakerRecords(speakers, userProfiles))
        .then(speakers => speakersIndex.addObjects(speakers))
}

const toSpeakerRecords = (speakers: WithId<SpeakerData>[], userProfiles: WithId<UserData>[]): SpeakerRecord[] => {
    return speakers.map(speaker => {
        const userProfile = userProfiles.find(it => it.id === speaker.user_profile.id)!!

        return {
            name: userProfile.full_name,
            objectID: speaker.id,
        }
    })
}<commit_msg>Fix merge errors in index-speakers.ts<commit_after>import { AlgoliaClient } from 'algoliasearch'
import { FirebaseApp } from '../firebase'

import { firestoreRawCollection, WithId } from '../firestore/collection'
import { SpeakerData, UserData } from '../firestore/data'
import { SpeakerRecord } from './records'

export const indexSpeakers = (firebaseApp: FirebaseApp, algolia: AlgoliaClient, indexPrefix: string): Promise<void> => {
    const speakersIndex = algolia.initIndex(`${indexPrefix}_speakers`)

    const rawCollection = firestoreRawCollection(firebaseApp)

    const speakersPromise = rawCollection<SpeakerData>('speakers')
    const userProfilesPromise = rawCollection<UserData>('user_profiles')

    return Promise.all([speakersPromise, userProfilesPromise])
        .then(([speakers, userProfiles]) => toSpeakerRecords(speakers, userProfiles))
        .then(speakers => speakersIndex.addObjects(speakers))
}

const toSpeakerRecords = (speakers: WithId<SpeakerData>[], userProfiles: WithId<UserData>[]): SpeakerRecord[] => {
    return speakers.map(speaker => {
        const userProfile = userProfiles.find(it => it.id === speaker.user_profile.id)!!

        return {
            name: userProfile.full_name,
            objectID: speaker.id,
        }
    })
}
{'fraction_non_alphanumeric': 0.12440570522979398, 'fraction_numerical': 0.0, 'mean_word_length': 4.477223427331888, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3854233', 'n_tokens_mistral': 730, 'n_tokens_neox': 714, 'n_words': 148}