diff options
author | Kegsay <kegan@matrix.org> | 2020-08-27 18:53:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 18:53:40 +0100 |
commit | 9af2f5f1f253a821cec660ef477c274d5cd13953 (patch) | |
tree | 998ff675429077b8db11142f15cb2fe1417f0194 /userapi/storage | |
parent | c0f28845f8715b13b4df8728909c7a55e0a2c63a (diff) |
Remove device DB from clientapi (#1352)
* Remove device DB from clientapi
* Remove device DB from startup configuration
It's all an impl detail now in user API
Diffstat (limited to 'userapi/storage')
-rw-r--r-- | userapi/storage/devices/interface.go | 3 | ||||
-rw-r--r-- | userapi/storage/devices/postgres/devices_table.go | 5 | ||||
-rw-r--r-- | userapi/storage/devices/postgres/storage.go | 11 | ||||
-rw-r--r-- | userapi/storage/devices/sqlite3/devices_table.go | 5 | ||||
-rw-r--r-- | userapi/storage/devices/sqlite3/storage.go | 11 |
5 files changed, 22 insertions, 13 deletions
diff --git a/userapi/storage/devices/interface.go b/userapi/storage/devices/interface.go index 3c9ec934..9b4261c9 100644 --- a/userapi/storage/devices/interface.go +++ b/userapi/storage/devices/interface.go @@ -35,5 +35,6 @@ type Database interface { UpdateDevice(ctx context.Context, localpart, deviceID string, displayName *string) error RemoveDevice(ctx context.Context, deviceID, localpart string) error RemoveDevices(ctx context.Context, localpart string, devices []string) error - RemoveAllDevices(ctx context.Context, localpart string) error + // RemoveAllDevices deleted all devices for this user. Returns the devices deleted. + RemoveAllDevices(ctx context.Context, localpart string) (devices []api.Device, err error) } diff --git a/userapi/storage/devices/postgres/devices_table.go b/userapi/storage/devices/postgres/devices_table.go index 03bf7c72..282466f8 100644 --- a/userapi/storage/devices/postgres/devices_table.go +++ b/userapi/storage/devices/postgres/devices_table.go @@ -251,11 +251,10 @@ func (s *devicesStatements) selectDevicesByID(ctx context.Context, deviceIDs []s } func (s *devicesStatements) selectDevicesByLocalpart( - ctx context.Context, localpart string, + ctx context.Context, txn *sql.Tx, localpart string, ) ([]api.Device, error) { devices := []api.Device{} - - rows, err := s.selectDevicesByLocalpartStmt.QueryContext(ctx, localpart) + rows, err := sqlutil.TxStmt(txn, s.selectDevicesByLocalpartStmt).QueryContext(ctx, localpart) if err != nil { return devices, err diff --git a/userapi/storage/devices/postgres/storage.go b/userapi/storage/devices/postgres/storage.go index 4a7c7f97..04dae986 100644 --- a/userapi/storage/devices/postgres/storage.go +++ b/userapi/storage/devices/postgres/storage.go @@ -68,7 +68,7 @@ func (d *Database) GetDeviceByID( func (d *Database) GetDevicesByLocalpart( ctx context.Context, localpart string, ) ([]api.Device, error) { - return d.devices.selectDevicesByLocalpart(ctx, localpart) + return d.devices.selectDevicesByLocalpart(ctx, nil, localpart) } func (d *Database) GetDevicesByID(ctx context.Context, deviceIDs []string) ([]api.Device, error) { @@ -176,11 +176,16 @@ func (d *Database) RemoveDevices( // If something went wrong during the deletion, it will return the SQL error. func (d *Database) RemoveAllDevices( ctx context.Context, localpart string, -) error { - return sqlutil.WithTransaction(d.db, func(txn *sql.Tx) error { +) (devices []api.Device, err error) { + err = sqlutil.WithTransaction(d.db, func(txn *sql.Tx) error { + devices, err = d.devices.selectDevicesByLocalpart(ctx, txn, localpart) + if err != nil { + return err + } if err := d.devices.deleteDevicesByLocalpart(ctx, txn, localpart); err != sql.ErrNoRows { return err } return nil }) + return } diff --git a/userapi/storage/devices/sqlite3/devices_table.go b/userapi/storage/devices/sqlite3/devices_table.go index c93e8b77..ecf43524 100644 --- a/userapi/storage/devices/sqlite3/devices_table.go +++ b/userapi/storage/devices/sqlite3/devices_table.go @@ -231,11 +231,10 @@ func (s *devicesStatements) selectDeviceByID( } func (s *devicesStatements) selectDevicesByLocalpart( - ctx context.Context, localpart string, + ctx context.Context, txn *sql.Tx, localpart string, ) ([]api.Device, error) { devices := []api.Device{} - - rows, err := s.selectDevicesByLocalpartStmt.QueryContext(ctx, localpart) + rows, err := sqlutil.TxStmt(txn, s.selectDevicesByLocalpartStmt).QueryContext(ctx, localpart) if err != nil { return devices, err diff --git a/userapi/storage/devices/sqlite3/storage.go b/userapi/storage/devices/sqlite3/storage.go index 4f426c6e..f775fb66 100644 --- a/userapi/storage/devices/sqlite3/storage.go +++ b/userapi/storage/devices/sqlite3/storage.go @@ -72,7 +72,7 @@ func (d *Database) GetDeviceByID( func (d *Database) GetDevicesByLocalpart( ctx context.Context, localpart string, ) ([]api.Device, error) { - return d.devices.selectDevicesByLocalpart(ctx, localpart) + return d.devices.selectDevicesByLocalpart(ctx, nil, localpart) } func (d *Database) GetDevicesByID(ctx context.Context, deviceIDs []string) ([]api.Device, error) { @@ -180,11 +180,16 @@ func (d *Database) RemoveDevices( // If something went wrong during the deletion, it will return the SQL error. func (d *Database) RemoveAllDevices( ctx context.Context, localpart string, -) error { - return d.writer.Do(d.db, nil, func(txn *sql.Tx) error { +) (devices []api.Device, err error) { + err = d.writer.Do(d.db, nil, func(txn *sql.Tx) error { + devices, err = d.devices.selectDevicesByLocalpart(ctx, txn, localpart) + if err != nil { + return err + } if err := d.devices.deleteDevicesByLocalpart(ctx, txn, localpart); err != sql.ErrNoRows { return err } return nil }) + return } |