Misc Performance Improvements (#105)

* Improves indexes

Increases batch size

* Fixes migration
This commit is contained in:
Chris Anderson 2023-03-31 15:59:08 -05:00 committed by GitHub
parent a273247809
commit 16e58a248c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 12 deletions

View file

@ -0,0 +1,17 @@
exports.up = async function(knex) {
await knex.schema
.alterTable('users', function(table) {
table.index('external_id')
table.index('anonymous_id')
table.index('project_id')
})
}
exports.down = async function(knex) {
await knex.schema
.alterTable('users', function(table) {
table.dropIndex('external_id')
table.dropIndex('anonymous_id')
table.dropIndex('project_id')
})
}

View file

@ -58,9 +58,9 @@ export default class RedisQueueProvider implements QueueProvider {
start(): void {
this.worker = new Worker('parcelvoy', async job => {
await this.queue.dequeue(job.data)
}, { connection: this.config, concurrency: 25 })
}, { connection: this.config, concurrency: this.batchSize })
this.worker.on('failed', (job, error) => {
logger.error({ error }, 'sqs:error:processing')
logger.error({ error }, 'redis:error:processing')
})
}

View file

@ -3,23 +3,26 @@ import { loadAnalytics } from '../providers/analytics'
import { User } from '../users/User'
import { UserEvent, UserEventParams } from './UserEvent'
export const createEvent = async (user: User, event: UserEventParams): Promise<number> => {
export const createEvent = async (user: User, event: UserEventParams, forward = true): Promise<number> => {
const data = {
project_id: user.project_id,
user_id: user.id,
...event,
}
const id = await UserEvent.insert(data)
const analytics = await loadAnalytics(user.project_id)
analytics.track({
external_id: user.external_id,
...event,
})
if (forward) {
const analytics = await loadAnalytics(user.project_id)
analytics.track({
external_id: user.external_id,
...event,
})
}
return id
}
export const createAndFetchEvent = async (user: User, event: UserEventParams): Promise<UserEvent> => {
const id = await createEvent(user, event)
export const createAndFetchEvent = async (user: User, event: UserEventParams, forward = false): Promise<UserEvent> => {
const id = await createEvent(user, event, forward)
const userEvent = await UserEvent.find(id)
return userEvent!
}

View file

@ -168,7 +168,7 @@ export function SearchTable<T extends Record<string, any>>({
}
{
filters.length > 0 && (
<Stack style={{ paddingBottom: 15 }}>
<Stack>
{filters}
</Stack>
)

View file

@ -3,7 +3,7 @@
display: flex;
flex-direction: row;
gap: var(--spacing);
padding-bottom: var(--spacing);
margin-bottom: var(--spacing);
}
.ui-stack.ui-stack-vertical {