mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-20 22:36:00 +02:00
minor code optimizations
This commit is contained in:
parent
1248421703
commit
b1a63bb98d
@ -423,7 +423,7 @@ func (dao *Dao) cascadeRecordDelete(mainRecord *models.Record, refs map[*models.
|
|||||||
// trigger cascade for each 1000 rel items until there is none
|
// trigger cascade for each 1000 rel items until there is none
|
||||||
batchSize := 1000
|
batchSize := 1000
|
||||||
for {
|
for {
|
||||||
rows := []dbx.NullStringMap{}
|
rows := make([]dbx.NullStringMap, 0, batchSize)
|
||||||
if err := query.Limit(int64(batchSize)).All(&rows); err != nil {
|
if err := query.Limit(int64(batchSize)).All(&rows); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -433,8 +433,8 @@ func (dao *Dao) cascadeRecordDelete(mainRecord *models.Record, refs map[*models.
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
perWorkers := 50
|
perWorker := 50
|
||||||
workers := int(math.Ceil(float64(total) / float64(perWorkers)))
|
workers := int(math.Ceil(float64(total) / float64(perWorker)))
|
||||||
|
|
||||||
batchErr := func() error {
|
batchErr := func() error {
|
||||||
ch := make(chan error)
|
ch := make(chan error)
|
||||||
@ -442,12 +442,12 @@ func (dao *Dao) cascadeRecordDelete(mainRecord *models.Record, refs map[*models.
|
|||||||
|
|
||||||
for i := 0; i < workers; i++ {
|
for i := 0; i < workers; i++ {
|
||||||
var chunks []dbx.NullStringMap
|
var chunks []dbx.NullStringMap
|
||||||
if len(rows) <= perWorkers {
|
if len(rows) <= perWorker {
|
||||||
chunks = rows
|
chunks = rows
|
||||||
rows = nil
|
rows = nil
|
||||||
} else {
|
} else {
|
||||||
chunks = rows[:perWorkers]
|
chunks = rows[:perWorker]
|
||||||
rows = rows[perWorkers:]
|
rows = rows[perWorker:]
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -176,7 +176,7 @@ func (dao *Dao) expandRecords(records []*models.Record, expandPath string, fetch
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reindex with the rel id
|
// reindex with the rel id
|
||||||
indexedRels := map[string]*models.Record{}
|
indexedRels := make(map[string]*models.Record, len(rels))
|
||||||
for _, rel := range rels {
|
for _, rel := range rels {
|
||||||
indexedRels[rel.GetId()] = rel
|
indexedRels[rel.GetId()] = rel
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user