mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
Initial syncapi storage refactor to share pq/sqlite code (#1030)
* Initial syncapi storage refactor to share pq/sqlite code This goes down a different route than https://github.com/matrix-org/dendrite/pull/985 which tried to even reduce the boilerplate of `ExecContext` etc. The previous pattern fails badly when there are subtle differences in parameters and hence the shared boilerplate to read from `QueryContext` breaks. Rather than attacking it at that level, the main place where we want to reuse code is for the `syncserver.go` itself - the database implementation which has lots of complex logic. So instead, this commit: - Makes `invites_table.go` an interface. - Makes `SyncServerDatasource` use that interface - This means some functions are now identical for pq/sqlite, so factor them out to a temporary `shared.Database` struct which will grow until it replaces all of `SyncServerDatasource`. * Missing files
This commit is contained in:
parent
bdddd83753
commit
a25d477cdb
6 changed files with 127 additions and 65 deletions
37
syncapi/storage/shared/syncserver.go
Normal file
37
syncapi/storage/shared/syncserver.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
// Database is a temporary struct until we have made syncserver.go the same for both pq/sqlite
|
||||
// For now this contains the shared functions
|
||||
type Database struct {
|
||||
DB *sql.DB
|
||||
Invites tables.Invites
|
||||
}
|
||||
|
||||
func (d *Database) AddInviteEvent(
|
||||
ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent,
|
||||
) (sp types.StreamPosition, err error) {
|
||||
err = common.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
sp, err = d.Invites.InsertInviteEvent(ctx, txn, inviteEvent)
|
||||
return err
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Database) RetireInviteEvent(
|
||||
ctx context.Context, inviteEventID string,
|
||||
) error {
|
||||
// TODO: Record that invite has been retired in a stream so that we can
|
||||
// notify the user in an incremental sync.
|
||||
err := d.Invites.DeleteInviteEvent(ctx, inviteEventID)
|
||||
return err
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue