sort cascadeDelete refs for deterministic tests output
This commit is contained in:
		
							parent
							
								
									c4116e3a7d
								
							
						
					
					
						commit
						0599955676
					
				|  | @ -5,6 +5,7 @@ import ( | |||
| 	"database/sql" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| 
 | ||||
| 	"github.com/pocketbase/dbx" | ||||
|  | @ -660,9 +661,23 @@ func (dao *Dao) DeleteRecord(record *models.Record) error { | |||
| func (dao *Dao) cascadeRecordDelete(mainRecord *models.Record, refs map[*models.Collection][]*schema.SchemaField) error { | ||||
| 	uniqueJsonEachAlias := "__je__" + security.PseudorandomString(4) | ||||
| 
 | ||||
| 	for refCollection, fields := range refs { | ||||
| 		if refCollection.IsView() { | ||||
| 			continue // skip view collections
 | ||||
| 	// @todo consider changing refs to a slice
 | ||||
| 	//
 | ||||
| 	// Sort the refs keys to ensure that the cascade events firing order is always the same.
 | ||||
| 	// This is not necessary for the operation to function correctly but it helps having deterministic output during testing.
 | ||||
| 	sortedRefKeys := make([]*models.Collection, 0, len(refs)) | ||||
| 	for k := range refs { | ||||
| 		sortedRefKeys = append(sortedRefKeys, k) | ||||
| 	} | ||||
| 	sort.Slice(sortedRefKeys, func(i, j int) bool { | ||||
| 		return sortedRefKeys[i].Name < sortedRefKeys[j].Name | ||||
| 	}) | ||||
| 
 | ||||
| 	for _, refCollection := range sortedRefKeys { | ||||
| 		fields, ok := refs[refCollection] | ||||
| 
 | ||||
| 		if refCollection.IsView() || !ok { | ||||
| 			continue // skip missing or view collections
 | ||||
| 		} | ||||
| 
 | ||||
| 		for _, field := range fields { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue