Skip to content

Commit

Permalink
only apply filter for insert and update
Browse files Browse the repository at this point in the history
  • Loading branch information
rwynn committed Feb 28, 2018
1 parent a4bbb88 commit d88eea2
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions monstache.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,36 +713,42 @@ func filterWithRegex(regex string) gtm.OpFilter {

func filterWithPlugin() gtm.OpFilter {
return func(op *gtm.Op) bool {
input := &monstachemap.MapperPluginInput{
Document: op.Data,
Namespace: op.Namespace,
Database: op.GetDatabase(),
Collection: op.GetCollection(),
Operation: op.Operation,
}
if ok, err := filterPlugin(input); err == nil {
return ok
} else {
errorLog.Println(err)
return false
var keep bool = true
if (op.IsInsert() || op.IsUpdate()) && op.Data != nil {
keep = false
input := &monstachemap.MapperPluginInput{
Document: op.Data,
Namespace: op.Namespace,
Database: op.GetDatabase(),
Collection: op.GetCollection(),
Operation: op.Operation,
}
if ok, err := filterPlugin(input); err == nil {
keep = ok
} else {
errorLog.Println(err)
}
}
return keep
}
}

func filterWithScript() gtm.OpFilter {
return func(op *gtm.Op) bool {
var keep bool = true
if env := filterEnvs[op.Namespace]; env != nil {
keep = false
arg := convertMapJavascript(op.Data)
val, err := env.VM.Call("module.exports", arg, arg)
if err != nil {
errorLog.Println(err)
} else {
if ok, err := val.ToBoolean(); err == nil {
keep = ok
} else {
if (op.IsInsert() || op.IsUpdate()) && op.Data != nil {
if env := filterEnvs[op.Namespace]; env != nil {
keep = false
arg := convertMapJavascript(op.Data)
val, err := env.VM.Call("module.exports", arg, arg)
if err != nil {
errorLog.Println(err)
} else {
if ok, err := val.ToBoolean(); err == nil {
keep = ok
} else {
errorLog.Println(err)
}
}
}
}
Expand Down

0 comments on commit d88eea2

Please sign in to comment.