mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-01 03:03:10 -06:00
UnsentFilter, review comments
This commit is contained in:
parent
e5d407d948
commit
5f68f61b42
|
|
@ -463,9 +463,22 @@ func (s *eventStatements) BulkSelectEventID(ctx context.Context, txn *sql.Tx, ev
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
||||||
|
// If an event ID is not in the database then it is omitted from the map.
|
||||||
|
func (s *eventStatements) BulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventNID, error) {
|
||||||
|
return s.bulkSelectEventNID(ctx, txn, eventIDs, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BulkSelectEventNIDs returns a map from string event ID to numeric event ID
|
||||||
|
// only for events that haven't already been sent to the roomserver output.
|
||||||
|
// If an event ID is not in the database then it is omitted from the map.
|
||||||
|
func (s *eventStatements) BulkSelectUnsentEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventNID, error) {
|
||||||
|
return s.bulkSelectEventNID(ctx, txn, eventIDs, true)
|
||||||
|
}
|
||||||
|
|
||||||
// bulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
// bulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
||||||
// If an event ID is not in the database then it is omitted from the map.
|
// If an event ID is not in the database then it is omitted from the map.
|
||||||
func (s *eventStatements) BulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool) (map[string]types.EventNID, error) {
|
func (s *eventStatements) bulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool) (map[string]types.EventNID, error) {
|
||||||
var stmt *sql.Stmt
|
var stmt *sql.Stmt
|
||||||
if onlyUnsent {
|
if onlyUnsent {
|
||||||
stmt = sqlutil.TxStmt(txn, s.bulkSelectUnsentEventNIDStmt)
|
stmt = sqlutil.TxStmt(txn, s.bulkSelectUnsentEventNIDStmt)
|
||||||
|
|
|
||||||
|
|
@ -215,13 +215,13 @@ func (u *RoomUpdater) EventIDs(
|
||||||
func (u *RoomUpdater) EventNIDs(
|
func (u *RoomUpdater) EventNIDs(
|
||||||
ctx context.Context, eventIDs []string,
|
ctx context.Context, eventIDs []string,
|
||||||
) (map[string]types.EventNID, error) {
|
) (map[string]types.EventNID, error) {
|
||||||
return u.d.eventNIDs(ctx, u.txn, eventIDs, false)
|
return u.d.eventNIDs(ctx, u.txn, eventIDs, NoFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *RoomUpdater) UnsentEventNIDs(
|
func (u *RoomUpdater) UnsentEventNIDs(
|
||||||
ctx context.Context, eventIDs []string,
|
ctx context.Context, eventIDs []string,
|
||||||
) (map[string]types.EventNID, error) {
|
) (map[string]types.EventNID, error) {
|
||||||
return u.d.eventNIDs(ctx, u.txn, eventIDs, true)
|
return u.d.eventNIDs(ctx, u.txn, eventIDs, FilterUnsentOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *RoomUpdater) StateAtEventIDs(
|
func (u *RoomUpdater) StateAtEventIDs(
|
||||||
|
|
|
||||||
|
|
@ -238,13 +238,27 @@ func (d *Database) addState(
|
||||||
func (d *Database) EventNIDs(
|
func (d *Database) EventNIDs(
|
||||||
ctx context.Context, eventIDs []string,
|
ctx context.Context, eventIDs []string,
|
||||||
) (map[string]types.EventNID, error) {
|
) (map[string]types.EventNID, error) {
|
||||||
return d.eventNIDs(ctx, nil, eventIDs, false)
|
return d.eventNIDs(ctx, nil, eventIDs, NoFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UnsentFilter bool
|
||||||
|
|
||||||
|
const (
|
||||||
|
NoFilter UnsentFilter = false
|
||||||
|
FilterUnsentOnly UnsentFilter = true
|
||||||
|
)
|
||||||
|
|
||||||
func (d *Database) eventNIDs(
|
func (d *Database) eventNIDs(
|
||||||
ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool,
|
ctx context.Context, txn *sql.Tx, eventIDs []string, filter UnsentFilter,
|
||||||
) (map[string]types.EventNID, error) {
|
) (map[string]types.EventNID, error) {
|
||||||
return d.EventsTable.BulkSelectEventNID(ctx, txn, eventIDs, onlyUnsent)
|
switch filter {
|
||||||
|
case FilterUnsentOnly:
|
||||||
|
return d.EventsTable.BulkSelectUnsentEventNID(ctx, txn, eventIDs)
|
||||||
|
case NoFilter:
|
||||||
|
return d.EventsTable.BulkSelectEventNID(ctx, txn, eventIDs)
|
||||||
|
default:
|
||||||
|
panic("impossible case")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) SetState(
|
func (d *Database) SetState(
|
||||||
|
|
@ -281,11 +295,11 @@ func (d *Database) EventIDs(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error) {
|
func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error) {
|
||||||
return d.eventsFromIDs(ctx, nil, eventIDs, false)
|
return d.eventsFromIDs(ctx, nil, eventIDs, NoFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Database) eventsFromIDs(ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool) ([]types.Event, error) {
|
func (d *Database) eventsFromIDs(ctx context.Context, txn *sql.Tx, eventIDs []string, filter UnsentFilter) ([]types.Event, error) {
|
||||||
nidMap, err := d.eventNIDs(ctx, txn, eventIDs, onlyUnsent)
|
nidMap, err := d.eventNIDs(ctx, txn, eventIDs, filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -499,9 +499,22 @@ func (s *eventStatements) BulkSelectEventID(ctx context.Context, txn *sql.Tx, ev
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
||||||
|
// If an event ID is not in the database then it is omitted from the map.
|
||||||
|
func (s *eventStatements) BulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventNID, error) {
|
||||||
|
return s.bulkSelectEventNID(ctx, txn, eventIDs, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// BulkSelectEventNIDs returns a map from string event ID to numeric event ID
|
||||||
|
// only for events that haven't already been sent to the roomserver output.
|
||||||
|
// If an event ID is not in the database then it is omitted from the map.
|
||||||
|
func (s *eventStatements) BulkSelectUnsentEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventNID, error) {
|
||||||
|
return s.bulkSelectEventNID(ctx, txn, eventIDs, true)
|
||||||
|
}
|
||||||
|
|
||||||
// bulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
// bulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
||||||
// If an event ID is not in the database then it is omitted from the map.
|
// If an event ID is not in the database then it is omitted from the map.
|
||||||
func (s *eventStatements) BulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool) (map[string]types.EventNID, error) {
|
func (s *eventStatements) bulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool) (map[string]types.EventNID, error) {
|
||||||
///////////////
|
///////////////
|
||||||
iEventIDs := make([]interface{}, len(eventIDs))
|
iEventIDs := make([]interface{}, len(eventIDs))
|
||||||
for k, v := range eventIDs {
|
for k, v := range eventIDs {
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ type Events interface {
|
||||||
BulkSelectEventID(ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID) (map[types.EventNID]string, error)
|
BulkSelectEventID(ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID) (map[types.EventNID]string, error)
|
||||||
// BulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
// BulkSelectEventNIDs returns a map from string event ID to numeric event ID.
|
||||||
// If an event ID is not in the database then it is omitted from the map.
|
// If an event ID is not in the database then it is omitted from the map.
|
||||||
BulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string, onlyUnsent bool) (map[string]types.EventNID, error)
|
BulkSelectEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventNID, error)
|
||||||
|
BulkSelectUnsentEventNID(ctx context.Context, txn *sql.Tx, eventIDs []string) (map[string]types.EventNID, error)
|
||||||
SelectMaxEventDepth(ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID) (int64, error)
|
SelectMaxEventDepth(ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID) (int64, error)
|
||||||
SelectRoomNIDsForEventNIDs(ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID) (roomNIDs map[types.EventNID]types.RoomNID, err error)
|
SelectRoomNIDsForEventNIDs(ctx context.Context, txn *sql.Tx, eventNIDs []types.EventNID) (roomNIDs map[types.EventNID]types.RoomNID, err error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue