mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-15 10:53:09 -06:00
Variable and type clarifications
Signed-off-by: Alex Chen <minecnly@gmail.com>
This commit is contained in:
parent
ac775bb79d
commit
1772d830da
|
|
@ -56,6 +56,9 @@ type redactionStatements struct {
|
|||
bulkUpdateValidationStatusStmt *sql.Stmt
|
||||
}
|
||||
|
||||
// redactedToRedactionMap is a map in the form map[redactedEventID]redactionEventNID.
|
||||
type redactedToRedactionMap map[string]types.EventNID
|
||||
|
||||
func (s *redactionStatements) prepare(db *sql.DB) (err error) {
|
||||
_, err = db.Exec(redactionsSchema)
|
||||
if err != nil {
|
||||
|
|
@ -81,13 +84,14 @@ func (s *redactionStatements) insertRedaction(
|
|||
return err
|
||||
}
|
||||
|
||||
// bulkSelectRedaction returns the redactions for the given event IDs.
|
||||
// Return values validated and unvalidated are both map[redactedEventID]redactedByNID.
|
||||
func (s *redactionStatements) bulkSelectRedaction(
|
||||
ctx context.Context,
|
||||
txn *sql.Tx,
|
||||
eventIDs []string,
|
||||
) (
|
||||
validated map[string]types.EventNID,
|
||||
unvalidated map[string]types.EventNID,
|
||||
validated, unvalidated redactedToRedactionMap,
|
||||
err error,
|
||||
) {
|
||||
stmt := common.TxStmt(txn, s.bulkSelectRedactionStmt)
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ func (d *Database) applyRedactions(
|
|||
}
|
||||
|
||||
if len(unvalidatedRedactions) != 0 {
|
||||
var newlyValidated map[string]types.EventNID
|
||||
var newlyValidated redactedToRedactionMap
|
||||
if newlyValidated, err = d.validateRedactions(
|
||||
ctx, unvalidatedRedactions, redactionNIDToEvent, eventIDToEventPointer,
|
||||
); err != nil {
|
||||
|
|
@ -325,7 +325,7 @@ func (d *Database) applyRedactions(
|
|||
|
||||
func (d *Database) fetchRedactionEvents(
|
||||
ctx context.Context,
|
||||
validatedRedactions, unvalidatedRedactions map[string]types.EventNID,
|
||||
validatedRedactions, unvalidatedRedactions redactedToRedactionMap,
|
||||
) (redactionNIDToEvent map[types.EventNID]*gomatrixserverlib.Event, err error) {
|
||||
redactionEventsToFetch := make([]types.EventNID, 0, len(validatedRedactions)+len(unvalidatedRedactions))
|
||||
for _, nid := range validatedRedactions {
|
||||
|
|
@ -354,15 +354,15 @@ func (d *Database) fetchRedactionEvents(
|
|||
|
||||
func (d *Database) validateRedactions(
|
||||
ctx context.Context,
|
||||
unvalidatedRedactions map[string]types.EventNID,
|
||||
unvalidatedRedactions redactedToRedactionMap,
|
||||
redactionNIDToEvent map[types.EventNID]*gomatrixserverlib.Event,
|
||||
eventIDToEvent map[string]*gomatrixserverlib.Event,
|
||||
) (validatedRedactions map[string]types.EventNID, err error) {
|
||||
validatedRedactions = make(map[string]types.EventNID, len(unvalidatedRedactions))
|
||||
redactedIDToEvent map[string]*gomatrixserverlib.Event,
|
||||
) (validatedRedactions redactedToRedactionMap, err error) {
|
||||
validatedRedactions = make(redactedToRedactionMap, len(unvalidatedRedactions))
|
||||
|
||||
for redactedEventID, redactedByNID := range unvalidatedRedactions {
|
||||
badEvents, needPowerLevelCheck, validationErr := common.ValidateRedaction(
|
||||
eventIDToEvent[redactedEventID], redactionNIDToEvent[redactedByNID],
|
||||
redactedIDToEvent[redactedEventID], redactionNIDToEvent[redactedByNID],
|
||||
)
|
||||
if validationErr != nil {
|
||||
return nil, validationErr
|
||||
|
|
|
|||
|
|
@ -982,13 +982,13 @@ func (d *SyncServerDatasource) validateRedactions(
|
|||
txn *sql.Tx,
|
||||
unvalidatedRedactions redactedToRedactionMap,
|
||||
redactionIDToEvent map[string]*gomatrixserverlib.Event,
|
||||
eventIDToEvent map[string]*gomatrixserverlib.Event,
|
||||
redactedIDToEvent map[string]*gomatrixserverlib.Event,
|
||||
) (validatedRedactions redactedToRedactionMap, err error) {
|
||||
validatedRedactions = make(redactedToRedactionMap, len(unvalidatedRedactions))
|
||||
|
||||
for redactedEventID, redactedByID := range unvalidatedRedactions {
|
||||
badEvents, needPowerLevelCheck, validationErr := common.ValidateRedaction(
|
||||
eventIDToEvent[redactedEventID], redactionIDToEvent[redactedByID],
|
||||
redactedIDToEvent[redactedEventID], redactionIDToEvent[redactedByID],
|
||||
)
|
||||
if validationErr != nil {
|
||||
return nil, validationErr
|
||||
|
|
|
|||
Loading…
Reference in a new issue