mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 02:25:30 +00:00
+Faster loading /baende
This commit is contained in:
@@ -30,6 +30,25 @@ func (a *Item) Entry() string {
|
||||
return a.GetString(ENTRIES_TABLE)
|
||||
}
|
||||
|
||||
func (i *Item) Entries() []string {
|
||||
// Get the raw string value of the 'entries' field
|
||||
raw := i.GetString(ENTRIES_TABLE)
|
||||
|
||||
// Check if it's likely a JSON array (starts with '[')
|
||||
if len(raw) > 0 && raw[0] == '[' {
|
||||
// If it is JSON, GetStringSlice will handle unmarshalling it
|
||||
return i.GetStringSlice(ENTRIES_TABLE)
|
||||
}
|
||||
|
||||
// If it's not a JSON array, it's a single ID. Return it as a slice.
|
||||
if raw != "" {
|
||||
return []string{raw}
|
||||
}
|
||||
|
||||
// Return an empty slice if the field is empty
|
||||
return []string{}
|
||||
}
|
||||
|
||||
func (a *Item) SetEntry(entry string) {
|
||||
a.Set(ENTRIES_TABLE, entry)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user