Skip to content

Commit

Permalink
Merge pull request #2891 from omnivore-app/disable-database-query-log…
Browse files Browse the repository at this point in the history
…-in-github-action

disable database query logs in github action
  • Loading branch information
sywhb authored Oct 10, 2023
2 parents a1122a3 + 1adbed9 commit fe30938
Show file tree
Hide file tree
Showing 23 changed files with 199 additions and 256 deletions.
28 changes: 1 addition & 27 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ jobs:
--health-retries 5
ports:
- 5432
elastic:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
env:
discovery.type: single-node
http.cors.allow-origin: '*'
http.cors.enabled: true
http.cors.allow-headers: 'X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization'
http.cors.allow-credentials: true
options: >-
--health-cmd "curl http://0.0.0.0:9200/_cluster/health"
--health-interval 10s
--health-timeout 5s
--health-retries 10
ports:
- 9200
redis:
image: redis
options: >-
Expand Down Expand Up @@ -82,22 +67,12 @@ jobs:
PG_USER: postgres
PG_PASSWORD: postgres
PG_DB: omnivore_test
ELASTIC_URL: http://localhost:${{ job.services.elastic.ports[9200] }}/
PGPASSWORD: postgres # This is required for the psql command to work without a password prompt
- name: TypeScript Build and Lint
run: |
source ~/.nvm/nvm.sh
yarn build
yarn lint
env:
PG_HOST: localhost
PG_PORT: ${{ job.services.postgres.ports[5432] }}
PG_USER: app_user
PG_PASSWORD: app_pass
PG_DB: omnivore_test
PG_POOL_MAX: 10
ELASTIC_URL: http://localhost:${{ job.services.elastic.ports[9200] }}/
REDIS_URL: redis://localhost:${{ job.services.redis.ports[6379] }}
- name: Tests
run: |
source ~/.nvm/nvm.sh
Expand All @@ -108,8 +83,7 @@ jobs:
PG_USER: app_user
PG_PASSWORD: app_pass
PG_DB: omnivore_test
PG_POOL_MAX: 10
ELASTIC_URL: http://localhost:${{ job.services.elastic.ports[9200] }}/
PG_LOGGER: debug
REDIS_URL: redis://localhost:${{ job.services.redis.ports[6379] }}
build-docker-images:
name: Build docker images
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import * as httpContext from 'express-http-context2'
import * as jwt from 'jsonwebtoken'
import { EntityManager } from 'typeorm'
import { promisify } from 'util'
import { appDataSource } from './data_source'
import { sanitizeDirectiveTransformer } from './directives'
import { env } from './env'
import { createPubSubClient } from './pubsub'
import { entityManager } from './repository'
import { functionResolvers } from './resolvers/function_resolvers'
import { ClaimsToSet, ResolverContext } from './resolvers/types'
import ScalarResolvers from './scalars'
Expand Down Expand Up @@ -79,7 +79,7 @@ const contextFunc: ContextFunction<ExpressContext, ResolverContext> = async ({
cb: (em: EntityManager) => TResult,
userRole?: string
): Promise<TResult> =>
entityManager.transaction(async (tx) => {
appDataSource.transaction(async (tx) => {
await setClaims(tx, undefined, userRole)
return cb(tx)
}),
Expand Down
37 changes: 0 additions & 37 deletions packages/api/src/events/entity_created.ts

This file was deleted.

34 changes: 34 additions & 0 deletions packages/api/src/events/user/profile_created.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
EntitySubscriberInterface,
EventSubscriber,
InsertEvent,
} from 'typeorm'
import { Profile } from '../../entity/profile'
import { createDefaultFiltersForUser } from '../../services/create_user'
import { addPopularReadsForNewUser } from '../../services/popular_reads'

@EventSubscriber()
export class AddPopularReadsToNewUser
implements EntitySubscriberInterface<Profile>
{
listenTo() {
return Profile
}

async afterInsert(event: InsertEvent<Profile>): Promise<void> {
await addPopularReadsForNewUser(event.entity.user.id, event.manager)
}
}

@EventSubscriber()
export class AddDefaultFiltersToNewUser
implements EntitySubscriberInterface<Profile>
{
listenTo() {
return Profile
}

async afterInsert(event: InsertEvent<Profile>): Promise<void> {
await createDefaultFiltersForUser(event.manager)(event.entity.user.id)
}
}
64 changes: 0 additions & 64 deletions packages/api/src/events/user/user_created.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/api/src/repository/highlight.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeepPartial } from 'typeorm'
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity'
import { entityManager } from '.'
import { appDataSource } from '../data_source'
import { Highlight } from '../entity/highlight'
import { unescapeHtml } from '../utils/helpers'

Expand All @@ -16,7 +16,7 @@ const unescapeHighlight = (highlight: DeepPartial<Highlight>) => {
return highlight
}

export const highlightRepository = entityManager
export const highlightRepository = appDataSource
.getRepository(Highlight)
.extend({
findById(id: string) {
Expand Down
6 changes: 2 additions & 4 deletions packages/api/src/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const setClaims = async (

export const authTrx = async <T>(
fn: (manager: EntityManager) => Promise<T>,
em = entityManager,
em = appDataSource.manager,
uid?: string,
userRole?: string
): Promise<T> => {
Expand All @@ -40,7 +40,5 @@ export const authTrx = async <T>(
}

export const getRepository = <T>(entity: EntityTarget<T>) => {
return entityManager.getRepository(entity)
return appDataSource.getRepository(entity)
}

export const entityManager = appDataSource.manager
4 changes: 2 additions & 2 deletions packages/api/src/repository/label.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { In } from 'typeorm'
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity'
import { entityManager } from '.'
import { appDataSource } from '../data_source'
import { Label } from '../entity/label'
import { generateRandomColor } from '../utils/helpers'

Expand Down Expand Up @@ -38,7 +38,7 @@ const convertToLabel = (label: CreateLabelInput, userId: string) => {
}
}

export const labelRepository = entityManager.getRepository(Label).extend({
export const labelRepository = appDataSource.getRepository(Label).extend({
findById(id: string) {
return this.findOneBy({ id })
},
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/repository/library_item.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { entityManager } from '.'
import { appDataSource } from '../data_source'
import { LibraryItem } from '../entity/library_item'

export const libraryItemRepository = entityManager
export const libraryItemRepository = appDataSource
.getRepository(LibraryItem)
.extend({
findById(id: string) {
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/repository/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { In } from 'typeorm'
import { entityManager } from '.'
import { appDataSource } from '../data_source'
import { User } from './../entity/user'

const TOP_USERS = [
Expand All @@ -14,7 +14,7 @@ const TOP_USERS = [
]
export const MAX_RECORDS_LIMIT = 1000

export const userRepository = entityManager.getRepository(User).extend({
export const userRepository = appDataSource.getRepository(User).extend({
findById(id: string) {
return this.findOneBy({ id })
},
Expand Down
55 changes: 33 additions & 22 deletions packages/api/src/services/create_user.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import { EntityManager } from 'typeorm'
import { appDataSource } from '../data_source'
import { Filter } from '../entity/filter'
import { GroupMembership } from '../entity/groups/group_membership'
import { Invite } from '../entity/groups/invite'
import { Profile } from '../entity/profile'
import { StatusType, User } from '../entity/user'
import { env } from '../env'
import { SignupErrorCode } from '../generated/graphql'
import { authTrx, entityManager, getRepository } from '../repository'
import { createPubSubClient } from '../pubsub'
import { authTrx, getRepository } from '../repository'
import { userRepository } from '../repository/user'
import { AuthProvider } from '../routers/auth/auth_types'
import { analytics } from '../utils/analytics'
import { IntercomClient } from '../utils/intercom'
import { logger } from '../utils/logger'
import { validateUsername } from '../utils/usernamePolicy'
import { sendConfirmationEmail } from './send_emails'
import { Filter } from '../entity/filter'
import { analytics } from '../utils/analytics'
import { env } from '../env'

const TOP_USERS = [
'jacksonh',
'nat',
'luis',
'satindar',
'malandrina',
'patrick',
'alexgutjahr',
'hongbowu',
]
export const MAX_RECORDS_LIMIT = 1000

export const createUser = async (input: {
Expand Down Expand Up @@ -71,7 +64,7 @@ export const createUser = async (input: {
return Promise.reject({ errorCode: SignupErrorCode.InvalidUsername })
}

const [user, profile] = await entityManager.transaction<[User, Profile]>(
const [user, profile] = await appDataSource.transaction<[User, Profile]>(
async (t) => {
let hasInvite = false
let invite: Invite | null = null
Expand Down Expand Up @@ -110,17 +103,29 @@ export const createUser = async (input: {
})
}

await createDefaultFiltersForUser(t)(user.id)

return [user, profile]
}
)

if (input.pendingConfirmation) {
if (!(await sendConfirmationEmail(user))) {
return Promise.reject({ errorCode: SignupErrorCode.InvalidEmail })
}
const customAttributes: { source_user_id: string } = {
source_user_id: user.sourceUserId,
}
await IntercomClient?.contacts.createUser({
email: user.email,
externalId: user.id,
name: user.name,
avatar: profile.pictureUrl || undefined,
customAttributes: customAttributes,
signedUpAt: Math.floor(Date.now() / 1000),
})

const pubsubClient = createPubSubClient()
await pubsubClient.userCreated(
user.id,
user.email,
user.name,
profile.username
)

analytics.track({
userId: user.id,
Expand All @@ -132,10 +137,16 @@ export const createUser = async (input: {
},
})

if (input.pendingConfirmation) {
if (!(await sendConfirmationEmail(user))) {
return Promise.reject({ errorCode: SignupErrorCode.InvalidEmail })
}
}

return [user, profile]
}

const createDefaultFiltersForUser =
export const createDefaultFiltersForUser =
(t: EntityManager) =>
async (userId: string): Promise<Filter[]> => {
const defaultFilters = [
Expand Down
Loading

1 comment on commit fe30938

@vercel
Copy link

@vercel vercel bot commented on fe30938 Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.