+Faster loading /baende

This commit is contained in:
Simon Martens
2026-01-25 01:36:52 +01:00
parent 6092c78aea
commit e8f5af132c
8 changed files with 593 additions and 264 deletions

View File

@@ -1,6 +1,10 @@
package dbmodels
import (
"fmt"
"strconv"
"strings"
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/core"
)
@@ -240,6 +244,37 @@ func Items_Entry(app core.App, id string) ([]*Item, error) {
return ret, err
}
func Items_Entries(app core.App, ids []any) ([]*Item, error) {
if len(ids) == 0 {
return []*Item{}, nil
}
params := dbx.Params{}
idPlaceholders := make([]string, len(ids))
for i, id := range ids {
placeholder := "p" + strconv.Itoa(i)
params[placeholder] = id
idPlaceholders[i] = "{:" + placeholder + "}"
}
inClause := strings.Join(idPlaceholders, ", ")
fullExpression := fmt.Sprintf(
"%s IN (%s) OR (json_valid(%s) = 1 AND EXISTS (SELECT 1 FROM json_each(%s) WHERE value IN (%s)))",
ENTRIES_TABLE,
inClause,
ENTRIES_TABLE,
ENTRIES_TABLE,
inClause,
)
var ret []*Item
err := app.RecordQuery(ITEMS_TABLE).
Where(dbx.NewExp(fullExpression, params)).
All(&ret)
return ret, err
}
func Contents_MusenalmID(app core.App, id string) (*Content, error) {
ret, err := TableByField[Content](app, CONTENTS_TABLE, MUSENALMID_FIELD, id)
return &ret, err