From 4d155c61ce8a037441ac72f58dfedd9182439d78 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 19 Apr 2018 13:33:04 +0100 Subject: [PATCH] Only run events when the document has changed --- db/define_test.go | 2 +- db/event.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/db/define_test.go b/db/define_test.go index 59b2cfea..08528e05 100644 --- a/db/define_test.go +++ b/db/define_test.go @@ -601,7 +601,7 @@ func TestDefine(t *testing.T) { So(res[6].Result, ShouldHaveLength, 1) So(res[7].Result, ShouldHaveLength, 1) So(res[8].Result, ShouldHaveLength, 1) - So(res[9].Result, ShouldHaveLength, 4) + So(res[9].Result, ShouldHaveLength, 3) }) diff --git a/db/event.go b/db/event.go index c857679b..6e021a06 100644 --- a/db/event.go +++ b/db/event.go @@ -25,6 +25,14 @@ import ( // table, and executes them in name order. func (d *document) event(ctx context.Context, met method) (err error) { + // If this document has not changed + // then there is no need to perform + // any registered events. + + if ok := d.changed(); !ok { + return + } + // Get the event values specified // for this table, loop through // them, and compute the events.