mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-04-22 15:57:52 +02:00
skip unnecessary validator in case the default pattern is used
This commit is contained in:
parent
7481c3f7f4
commit
35196674e6
@ -28,6 +28,8 @@ const (
|
|||||||
|
|
||||||
const systemHookIdCollection = "__pbCollectionSystemHook__"
|
const systemHookIdCollection = "__pbCollectionSystemHook__"
|
||||||
|
|
||||||
|
const defaultLowercaseRecordIdPattern = "^[a-z0-9]+$"
|
||||||
|
|
||||||
func (app *BaseApp) registerCollectionHooks() {
|
func (app *BaseApp) registerCollectionHooks() {
|
||||||
app.OnModelValidate().Bind(&hook.Handler[*ModelEvent]{
|
app.OnModelValidate().Bind(&hook.Handler[*ModelEvent]{
|
||||||
Id: systemHookIdCollection,
|
Id: systemHookIdCollection,
|
||||||
@ -890,7 +892,7 @@ func (c *Collection) initIdField() {
|
|||||||
Required: true,
|
Required: true,
|
||||||
Min: 15,
|
Min: 15,
|
||||||
Max: 15,
|
Max: 15,
|
||||||
Pattern: `^[a-z0-9]+$`,
|
Pattern: defaultLowercaseRecordIdPattern,
|
||||||
AutogeneratePattern: `[a-z0-9]{15}`,
|
AutogeneratePattern: `[a-z0-9]{15}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -903,7 +905,7 @@ func (c *Collection) initIdField() {
|
|||||||
field.PrimaryKey = true
|
field.PrimaryKey = true
|
||||||
field.Hidden = false
|
field.Hidden = false
|
||||||
if field.Pattern == "" {
|
if field.Pattern == "" {
|
||||||
field.Pattern = `^[a-z0-9]+$`
|
field.Pattern = defaultLowercaseRecordIdPattern
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,6 +192,7 @@ func (f *TextField) ValidateValue(ctx context.Context, app App, record *Record)
|
|||||||
// side-effects on some platforms check for duplicates in a case-insensitive manner
|
// side-effects on some platforms check for duplicates in a case-insensitive manner
|
||||||
//
|
//
|
||||||
// (@todo eventually may get replaced in the future with a system unique constraint to avoid races or wrapping the request in a transaction)
|
// (@todo eventually may get replaced in the future with a system unique constraint to avoid races or wrapping the request in a transaction)
|
||||||
|
if f.Pattern != defaultLowercaseRecordIdPattern {
|
||||||
var exists bool
|
var exists bool
|
||||||
err := app.DB().
|
err := app.DB().
|
||||||
Select("(1)").
|
Select("(1)").
|
||||||
@ -204,6 +205,7 @@ func (f *TextField) ValidateValue(ctx context.Context, app App, record *Record)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return f.ValidatePlainValue(newVal)
|
return f.ValidatePlainValue(newVal)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user