@@ -9,7 +9,6 @@ import { injectable, inject } from "inversify";
9
9
import { TypeORM } from "./typeorm" ;
10
10
import { UserStorageResourcesDB } from "../user-storage-resources-db" ;
11
11
import { DBUserStorageResource } from "./entity/db-user-storage-resource" ;
12
- import { log } from '@gitpod/gitpod-protocol/lib/util/logging' ;
13
12
14
13
@injectable ( )
15
14
export class TypeORMUserStorageResourcesDBImpl implements UserStorageResourcesDB {
@@ -31,19 +30,16 @@ export class TypeORMUserStorageResourcesDBImpl implements UserStorageResourcesDB
31
30
}
32
31
33
32
async update ( userId : string , uri : string , content : string ) : Promise < void > {
33
+ // docs: https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
34
34
const repo = await this . getUserStorageResourceRepo ( ) ;
35
- let resource = await this . getResource ( userId , uri ) ;
36
- if ( resource ) {
37
- log . info ( { userId } , 'updating resource' , { uri } ) ;
38
- await repo . update ( resource , { content } ) ;
39
- } else {
40
- log . info ( { userId } , 'saving resource' , { uri } ) ;
41
- resource = new DBUserStorageResource ( ) ;
42
- resource . userId = userId ;
43
- resource . uri = uri ;
44
- resource . content = content ;
45
- await repo . save ( resource ) ;
46
- }
35
+ await repo . query ( `
36
+ INSERT INTO d_b_user_storage_resource
37
+ (userId, uri, content)
38
+ VALUES
39
+ (?, ?, ?)
40
+ ON DUPLICATE KEY UPDATE
41
+ content = VALUES(content);
42
+ ` , [ userId , uri , content ] ) ;
47
43
}
48
44
49
45
async deleteAllForUser ( userId : string ) : Promise < void > {
0 commit comments