Skip to content

Commit

Permalink
fix(db): mem leak caused by wrong data type for channel user attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rndlaine committed Jan 11, 2019
1 parent 51970ba commit b2c5017
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -50,7 +50,7 @@
"mustache": "^3.0.0",
"nanoid": "^1.2.3",
"node-machine-id": "^1.1.10",
"pg": "^7.4.3",
"pg": "^7.8.0",
"plur": "^3.0.1",
"portfinder": "^1.0.19",
"querystring": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/bp/core/database/tables/server-wide/channel_users.ts
Expand Up @@ -8,7 +8,7 @@ export class ChannelUsersTable extends Table {
await this.knex.createTableIfNotExists(this.name, table => {
table.string('channel')
table.string('user_id')
table.text('attributes')
table.json('attributes')
table.timestamps(true, true)
created = true
})
Expand Down
25 changes: 10 additions & 15 deletions src/bp/core/repositories/users.ts
Expand Up @@ -47,20 +47,15 @@ export class KnexUserRepository implements UserRepository {
return { result: user, created: false }
}

await this.database.knex(this.tableName).insert({
channel,
user_id: id,
attributes: this.database.knex.json.set({})
})

const newUser: User = {
attributes: {},
channel: channel,
id,
createdOn: new Date(),
updatedOn: new Date(),
otherChannels: []
}
const newUser = await this.database.knex.insertAndRetrieve<User>(
this.tableName,
{
channel,
user_id: id,
attributes: this.database.knex.json.set({})
},
['attributes', 'channel', 'created_at', 'updated_at']
)

return { result: newUser, created: true }
}
Expand All @@ -79,7 +74,7 @@ export class KnexUserRepository implements UserRepository {
async updateAttributes(channel: string, user_id: string, attributes: any): Promise<void> {
channel = channel.toLowerCase()

if (await this.dataRetentionService.hasPolicy()) {
if (this.dataRetentionService.hasPolicy()) {
const originalAttributes = await this.getAttributes(channel, user_id)
await this.dataRetentionService.updateExpirationForChangedFields(channel, user_id, originalAttributes, attributes)
}
Expand Down

0 comments on commit b2c5017

Please sign in to comment.