Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove a lot of fields from user data blob #3150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions backend/scripts/delete-user-fields.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
update users set data = data
- 'name'
- 'username'
- 'profitCached'
- 'portfolioHistory'
- 'createdTime'
- 'balance'
- 'spiceBalance'
- 'totalDeposits'
- 'totalCashDeposits'
- 'metricsLastUpdated'
- 'marketsCreatedThisWeek'
- 'lastPingTime'
- 'bountyTxns'
29 changes: 11 additions & 18 deletions backend/shared/src/create-user-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { STARTING_BALANCE } from 'common/economy'
import { ValidatedAPIParams } from 'common/api/schema'
import { APIError } from 'common/api/utils'
import { onCreateUser } from 'shared/helpers/on-create-user'
import { convertPrivateUser, convertUser } from 'common/supabase/users'

export const createUserMain = async (
props: ValidatedAPIParams<'createuser'>,
Expand Down Expand Up @@ -108,17 +109,9 @@ export const createUserMain = async (
throw new APIError(403, 'Username already taken', { username })

// Only undefined prop should be fromLove
const user: User = removeUndefinedProps({
const userData: Partial<User> = removeUndefinedProps({
id: userId,
name,
username,
avatarUrl,
balance: 0,
cashBalance: 0,
spiceBalance: 0,
totalDeposits: 0,
totalCashDeposits: 0,
createdTime: Date.now(),
nextLoanCached: 0,
streakForgiveness: 1,
shouldShowWelcome: true,
Expand All @@ -144,19 +137,19 @@ export const createUserMain = async (
blockedGroupSlugs: [],
}

await insert(tx, 'users', {
id: user.id,
name: user.name,
username: user.username,
data: user,
const userRow = await insert(tx, 'users', {
id: userId,
name: name,
username: username,
data: userData,
})

const startingBonusTxn: Omit<
SignupBonusTxn,
'id' | 'createdTime' | 'fromId'
> = {
fromType: 'BANK',
toId: user.id,
toId: userId,
toType: 'USER',
amount: STARTING_BALANCE,
token: 'M$',
Expand All @@ -165,14 +158,14 @@ export const createUserMain = async (
}
await runTxnFromBank(tx, startingBonusTxn)

await insert(tx, 'private_users', {
const privateUserRow = await insert(tx, 'private_users', {
id: privateUser.id,
data: privateUser,
})

return {
user,
privateUser,
user: convertUser(userRow),
privateUser: convertPrivateUser(privateUserRow),
}
})

Expand Down
Loading