Use functions

This commit is contained in:
Neil Alexander 2020-06-30 14:12:38 +01:00
parent a6aaa5aa52
commit f31be26df4
4 changed files with 8 additions and 16 deletions

View file

@ -121,7 +121,7 @@ func (oqs *OutgoingQueues) SendEvent(
"destinations": destinations, "event": ev.EventID(),
}).Info("Sending event")
nid, err := oqs.db.StoreJSON(context.TODO(), ev.JSON())
nid, err := oqs.db.StoreJSON(context.TODO(), string(ev.JSON()))
if err != nil {
return fmt.Errorf("sendevent: oqs.db.StoreJSON: %w", err)
}

View file

@ -26,7 +26,7 @@ type Database interface {
internal.PartitionStorer
UpdateRoom(ctx context.Context, roomID, oldEventID, newEventID string, addHosts []types.JoinedHost, removeHosts []string) (joinedHosts []types.JoinedHost, err error)
GetJoinedHosts(ctx context.Context, roomID string) ([]types.JoinedHost, error)
StoreJSON(ctx context.Context, js []byte) (int64, error)
StoreJSON(ctx context.Context, js string) (int64, error)
AssociatePDUWithDestination(ctx context.Context, transactionID gomatrixserverlib.TransactionID, serverName gomatrixserverlib.ServerName, nids []int64) error
GetNextTransactionPDUs(ctx context.Context, serverName gomatrixserverlib.ServerName, limit int) (gomatrixserverlib.TransactionID, []*gomatrixserverlib.HeaderedEvent, error)
CleanTransactionPDUs(ctx context.Context, serverName gomatrixserverlib.ServerName, transactionID gomatrixserverlib.TransactionID) error

View file

@ -138,15 +138,11 @@ func (d *Database) GetJoinedHosts(
// a NID. The NID will then be used when inserting the per-destination
// metadata entries.
func (d *Database) StoreJSON(
ctx context.Context, js []byte,
ctx context.Context, js string,
) (int64, error) {
res, err := d.insertJSONStmt.ExecContext(ctx, js)
nid, err := d.insertQueueJSON(ctx, nil, js)
if err != nil {
return 0, fmt.Errorf("d.insertRetryJSONStmt: %w", err)
}
nid, err := res.LastInsertId()
if err != nil {
return 0, fmt.Errorf("res.LastInsertID: %w", err)
return 0, fmt.Errorf("d.insertQueueJSON: %w", err)
}
return nid, nil
}

View file

@ -144,15 +144,11 @@ func (d *Database) GetJoinedHosts(
// a NID. The NID will then be used when inserting the per-destination
// metadata entries.
func (d *Database) StoreJSON(
ctx context.Context, js []byte,
ctx context.Context, js string,
) (int64, error) {
res, err := d.insertJSONStmt.ExecContext(ctx, js)
nid, err := d.insertQueueJSON(ctx, nil, js)
if err != nil {
return 0, fmt.Errorf("d.insertRetryJSONStmt: %w", err)
}
nid, err := res.LastInsertId()
if err != nil {
return 0, fmt.Errorf("res.LastInsertID: %w", err)
return 0, fmt.Errorf("d.insertQueueJSON: %w", err)
}
return nid, nil
}