Skip to content

Commit

Permalink
chore: remove pg-typed part 1 (#9508)
Browse files Browse the repository at this point in the history
* chore: refactor archive team

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* remove archivedTeam sql

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* refactor addNewFeature sql

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* chore: refactor add/remove reactjis

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* chore: refactor add/remove feature flags

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* chore: refactor appendUserTmsQuery

Signed-off-by: Matt Krick <matt.krick@gmail.com>

* fix: revert sharp back to v0.32.6 (#9509)

Signed-off-by: Matt Krick <matt.krick@gmail.com>

---------

Signed-off-by: Matt Krick <matt.krick@gmail.com>
  • Loading branch information
mattkrick authored Mar 6, 2024
1 parent fe1ad43 commit 5dfe26b
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 120 deletions.
20 changes: 12 additions & 8 deletions packages/server/billing/helpers/teamLimitsCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@ import ms from 'ms'
import {Threshold} from 'parabol-client/types/constEnums'
// Uncomment for easier testing
// import { ThresholdTest as Threshold } from "~/types/constEnums";
import {sql} from 'kysely'
import {r} from 'rethinkdb-ts'
import NotificationTeamsLimitExceeded from '../../database/types/NotificationTeamsLimitExceeded'
import Organization from '../../database/types/Organization'
import scheduleTeamLimitsJobs from '../../database/types/scheduleTeamLimitsJobs'
import {DataLoaderWorker} from '../../graphql/graphql'
import publishNotification from '../../graphql/public/mutations/helpers/publishNotification'
import getActiveTeamCountByTeamIds from '../../graphql/public/types/helpers/getActiveTeamCountByTeamIds'
import {getFeatureTier} from '../../graphql/types/helpers/getFeatureTier'
import {domainHasActiveDeals} from '../../hubSpot/hubSpotApi'
import getPg from '../../postgres/getPg'
import {appendUserFeatureFlagsQuery} from '../../postgres/queries/generated/appendUserFeatureFlagsQuery'
import getKysely from '../../postgres/getKysely'
import getTeamIdsByOrgIds from '../../postgres/queries/getTeamIdsByOrgIds'
import {getBillingLeadersByOrgId} from '../../utils/getBillingLeadersByOrgId'
import sendToSentry from '../../utils/sendToSentry'
import removeTeamsLimitObjects from './removeTeamsLimitObjects'
import sendTeamsLimitEmail from './sendTeamsLimitEmail'
import getTeamIdsByOrgIds from '../../postgres/queries/getTeamIdsByOrgIds'
import getActiveTeamCountByTeamIds from '../../graphql/public/types/helpers/getActiveTeamCountByTeamIds'
import {getBillingLeadersByOrgId} from '../../utils/getBillingLeadersByOrgId'
import {getFeatureTier} from '../../graphql/types/helpers/getFeatureTier'

const enableUsageStats = async (userIds: string[], orgId: string) => {
const pg = getKysely()
await r
.table('OrganizationUser')
.getAll(r.args(userIds), {index: 'userId'})
.filter({orgId})
.update({suggestedTier: 'team'})
.run()

await appendUserFeatureFlagsQuery.run({ids: userIds, flag: 'insights'}, getPg())
await pg
.updateTable('User')
.set({featureFlags: sql`arr_append_uniq("featureFlags", 'insights')`})
.where('id', 'in', userIds)
.execute()
}

const sendWebsiteNotifications = async (
Expand Down
6 changes: 3 additions & 3 deletions packages/server/graphql/private/mutations/addNewFeature.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getRethink from '../../../database/rethinkDriver'
import generateUID from '../../../generateUID'
import getPg from '../../../postgres/getPg'
import {addUserNewFeatureQuery} from '../../../postgres/queries/generated/addUserNewFeatureQuery'
import getKysely from '../../../postgres/getKysely'
import getRedis from '../../../utils/getRedis'
import publish from '../../../utils/publish'
import sendToSentry from '../../../utils/sendToSentry'
Expand All @@ -15,6 +14,7 @@ const addNewFeature: MutationResolvers['addNewFeature'] = async (
) => {
const r = await getRethink()
const redis = getRedis()
const pg = getKysely()

// AUTH
const operationId = dataLoader.share()
Expand All @@ -30,7 +30,7 @@ const addNewFeature: MutationResolvers['addNewFeature'] = async (
}
await Promise.all([
r.table('NewFeature').insert(newFeature).run(),
addUserNewFeatureQuery.run({newFeatureId}, getPg())
pg.updateTable('User').set({newFeatureId}).execute()
])

const onlineUserIds = new Set()
Expand Down
34 changes: 18 additions & 16 deletions packages/server/graphql/public/mutations/addReactjiToReactable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ import {RDatum} from '../../../database/stricterR'
import Comment from '../../../database/types/Comment'
import {Reactable} from '../../../database/types/Reactable'
import Reflection from '../../../database/types/Reflection'
import getPg from '../../../postgres/getPg'
import {appendTeamResponseReactji} from '../../../postgres/queries/generated/appendTeamResponseReactjiQuery'
import {removeTeamResponseReactji} from '../../../postgres/queries/generated/removeTeamResponseReactjiQuery'
import {analytics} from '../../../utils/analytics/analytics'
import {getUserId} from '../../../utils/authorization'
import emojiIds from '../../../utils/emojiIds'
import getGroupedReactjis from '../../../utils/getGroupedReactjis'
import publish from '../../../utils/publish'
import {GQLContext} from '../../graphql'

import getReactableType from '../../types/getReactableType'
import {ReactableEnumType} from '../../types/ReactableEnum'
import getKysely from '../../../postgres/getKysely'
import {AnyMeeting} from '../../../postgres/types/Meeting'
import {sql} from 'kysely'
import MeetingRetrospective from '../../../database/types/MeetingRetrospective'
import NotificationKudosReceived from '../../../database/types/NotificationKudosReceived'
import getKysely from '../../../postgres/getKysely'
import {TeamPromptResponse} from '../../../postgres/queries/getTeamPromptResponsesByIds'
import {AnyMeeting} from '../../../postgres/types/Meeting'
import {ReactableEnumType} from '../../types/ReactableEnum'
import getReactableType from '../../types/getReactableType'
import {MutationResolvers} from '../resolverTypes'
import NotificationKudosReceived from '../../../database/types/NotificationKudosReceived'
import publishNotification from './helpers/publishNotification'

const rethinkTableLookup = {
Expand Down Expand Up @@ -129,15 +127,19 @@ const addReactjiToReactable: MutationResolvers['addReactjiToReactable'] = async
if (pgLoaderName) {
const numberReactableId = TeamPromptResponseId.split(reactableId)
if (isRemove) {
await removeTeamResponseReactji.run(
{id: numberReactableId, reactji: {shortname: reactji, userid: viewerId}},
getPg()
)
await pg
.updateTable('TeamPromptResponse')
.set({reactjis: sql`array_remove("reactjis", (${reactji},${viewerId})::"Reactji")`})
.where('id', '=', numberReactableId)
.execute()
} else {
await appendTeamResponseReactji.run(
{id: numberReactableId, reactji: {shortname: reactji, userid: viewerId}},
getPg()
)
await pg
.updateTable('TeamPromptResponse')
.set({
reactjis: sql`arr_append_uniq("reactjis", (${reactji},${viewerId})::"Reactji")`
})
.where('id', '=', numberReactableId)
.execute()
}

dataLoader.get(pgLoaderName).clear(reactableId)
Expand Down
14 changes: 8 additions & 6 deletions packages/server/graphql/public/mutations/updateFeatureFlag.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ValueExpression, sql} from 'kysely'
import {SubscriptionChannel} from 'parabol-client/types/constEnums'
import getPg from '../../../postgres/getPg'
import {appendUserFeatureFlagsQuery} from '../../../postgres/queries/generated/appendUserFeatureFlagsQuery'
import {removeUserFeatureFlagsQuery} from '../../../postgres/queries/generated/removeUserFeatureFlagsQuery'
import getKysely from '../../../postgres/getKysely'
import {DB} from '../../../postgres/pg'
import getUsersByDomain from '../../../postgres/queries/getUsersByDomain'
import {getUsersByEmails} from '../../../postgres/queries/getUsersByEmails'
import IUser from '../../../postgres/types/IUser'
Expand All @@ -17,6 +17,7 @@ const updateFeatureFlag: MutationResolvers['updateFeatureFlag'] = async (
) => {
const operationId = dataLoader.share()
const subOptions = {operationId}
const pg = getKysely()

// AUTH
const viewerId = getUserId(authToken)
Expand All @@ -43,9 +44,10 @@ const updateFeatureFlag: MutationResolvers['updateFeatureFlag'] = async (
}

const userIds = isUpdatingViewerFlag ? [viewerId] : users.map(({id}) => id)
addFlag
? await appendUserFeatureFlagsQuery.run({ids: userIds, flag}, getPg())
: await removeUserFeatureFlagsQuery.run({ids: userIds, flag}, getPg())
const featureFlags: ValueExpression<DB, 'User', string[]> = addFlag
? sql`arr_append_uniq("featureFlags", ${flag})`
: sql`array_remove("featureFlags", ${flag})`
await pg.updateTable('User').set({featureFlags}).where('id', 'in', userIds).execute()
userIds.forEach((userId) => {
const data = {userId}
publish(SubscriptionChannel.NOTIFICATION, userId, 'UpdateFeatureFlagPayload', data, subOptions)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"rethinkdb-ts": "2.6.0",
"rrule": "^2.7.2",
"samlify": "^2.8.2",
"sharp": "^0.33.2",
"sharp": "^0.32.6",
"string-similarity": "^3.0.0",
"stripe": "^9.13.0",
"tslib": "^2.4.0",
Expand Down
17 changes: 0 additions & 17 deletions packages/server/postgres/queries/archiveTeamsByTeamIds.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions packages/server/postgres/queries/src/appendUserTmsQuery.sql

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 8 additions & 3 deletions packages/server/safeMutations/addTeamIdToTMS.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import getPg from '../postgres/getPg'
import {appendUserTmsQuery} from '../postgres/queries/generated/appendUserTmsQuery'
import {sql} from 'kysely'
import getKysely from '../postgres/getKysely'

const addTeamIdToTMS = async (userId: string, teamId: string) => {
return appendUserTmsQuery.run({id: userId, teamId}, getPg())
const pg = getKysely()
return pg
.updateTable('User')
.set({tms: sql`arr_append_uniq("tms", ${teamId})`})
.where('id', '=', userId)
.execute()
}

export default addTeamIdToTMS
12 changes: 9 additions & 3 deletions packages/server/safeMutations/safeArchiveTeam.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import getRethink from '../database/rethinkDriver'
import {RDatum} from '../database/stricterR'
import {DataLoaderWorker} from '../graphql/graphql'
import archiveTeamsByTeamIds from '../postgres/queries/archiveTeamsByTeamIds'
import getKysely from '../postgres/getKysely'
import removeUserTms from '../postgres/queries/removeUserTms'

const safeArchiveTeam = async (teamId: string, dataLoader: DataLoaderWorker) => {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const userIds = await r
.table('TeamMember')
Expand Down Expand Up @@ -34,10 +35,15 @@ const safeArchiveTeam = async (teamId: string, dataLoader: DataLoaderWorker) =>
)('changes')('new_val')('id')
.default([]) as unknown as string[]
}).run(),
archiveTeamsByTeamIds(teamId)
pg
.updateTable('Team')
.set({isArchived: true})
.where('id', '=', teamId)
.returningAll()
.executeTakeFirst()
])

return {...rethinkResult, team: pgResult[0] ?? null, users}
return {...rethinkResult, team: pgResult ?? null, users}
}

export default safeArchiveTeam
15 changes: 7 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9627,9 +9627,9 @@ camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001426, caniuse-lite@^1.0.30001517, caniuse-lite@^1.0.30001580, caniuse-lite@~1.0.0:
version "1.0.30001591"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001591.tgz#16745e50263edc9f395895a7cd468b9f3767cf33"
integrity sha512-PCzRMei/vXjJyL5mJtzNiUCKP59dm8Apqc3PH8gJkMnMXZGox93RbE76jHsmLwmIo6/3nsYIpJtx0O7u5PqFuQ==
version "1.0.30001594"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001594.tgz#bea552414cd52c2d0c985ed9206314a696e685f5"
integrity sha512-VblSX6nYqyJVs8DKFMldE2IVCJjZ225LW00ydtUWwh5hk9IfkTOffO6r8gJNsH0qqqeAF8KrbMYA2VEwTlGW5g==

capital-case@^1.0.4:
version "1.0.4"
Expand Down Expand Up @@ -11223,7 +11223,6 @@ draft-js-utils@^1.4.0:

"draft-js@https://github.com/mattkrick/draft-js/tarball/559a21968370c4944511657817d601a6c4ade0f6":
version "0.10.5"
uid "025fddba56f21aaf3383aee778e0b17025c9a7bc"
resolved "https://github.com/mattkrick/draft-js/tarball/559a21968370c4944511657817d601a6c4ade0f6#025fddba56f21aaf3383aee778e0b17025c9a7bc"
dependencies:
fbjs "^0.8.15"
Expand Down Expand Up @@ -16844,10 +16843,10 @@ osenv@^0.1.4:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"

oy-vey@^0.11.0:
version "0.11.2"
resolved "https://registry.yarnpkg.com/oy-vey/-/oy-vey-0.11.2.tgz#3bbc36a4064993a2ff52f985b066d44dcb4500d9"
integrity sha512-06prDST4MicbAWie4eXcouJbGhAu0r7j3Yta1KFtgs7v2t7goHmY06/GWFjT6lpIsGKJC+7vZtwdecRSYnFtPQ==
oy-vey@^0.12.1:
version "0.12.1"
resolved "https://registry.yarnpkg.com/oy-vey/-/oy-vey-0.12.1.tgz#a3bdda93bdb3a9f483fc01432b7b8d5abf838405"
integrity sha512-fFpS8mRoXqMTPYXUoDTO6S5S8WXvqBE+AOPbDwxFu2n3ZNns6x3+Ml/49lAomyJV6RzdFBVA5LxCUEHNaLlhjA==
dependencies:
clean-css "^4.0.12"
object-assign "^4.1.1"
Expand Down

0 comments on commit 5dfe26b

Please sign in to comment.