Improve live query performance and simplicity
This commit is contained in:
parent
5d5fdc296f
commit
9b03178dfd
3 changed files with 75 additions and 71 deletions
|
@ -28,7 +28,7 @@ var sockets sync.Map
|
|||
func register(fib *fibre.Context, id string) func() {
|
||||
return func() {
|
||||
|
||||
sockets.LoadOrStore(id, &socket{
|
||||
sockets.Store(id, &socket{
|
||||
fibre: fib,
|
||||
items: make(map[string][]interface{}),
|
||||
lives: make(map[string]*sql.LiveStatement),
|
||||
|
|
26
db/lives.go
26
db/lives.go
|
@ -47,10 +47,24 @@ func (d *document) lives(ctx context.Context, when method) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
if len(lvs) > 0 {
|
||||
// Loop over the currently running
|
||||
// live queries so that we can pass
|
||||
// change notifications to the socket.
|
||||
|
||||
for _, lv := range lvs {
|
||||
|
||||
// Check whether the change was made by
|
||||
// the same connection as the live query,
|
||||
// and if it is then don't notify changes.
|
||||
|
||||
if id == lv.FB {
|
||||
continue
|
||||
}
|
||||
|
||||
// Load the socket which owns the live
|
||||
// query so that we can check the socket
|
||||
// permissions, and send the notifications.
|
||||
|
||||
if sck, ok := sockets.Load(lv.FB); ok {
|
||||
|
||||
var out interface{}
|
||||
|
@ -61,14 +75,6 @@ func (d *document) lives(ctx context.Context, when method) (err error) {
|
|||
|
||||
ctx = sck.(*socket).ctx(d.ns, d.db)
|
||||
|
||||
// Check whether the change was made by
|
||||
// the same connection as the live query,
|
||||
// and if it is then don't notify changes.
|
||||
|
||||
if id == lv.FB {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check whether this live query has the
|
||||
// necessary permissions to view this
|
||||
// document, or continue to the next query.
|
||||
|
@ -128,8 +134,6 @@ func (d *document) lives(ctx context.Context, when method) (err error) {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ func (s *socket) clear(id string) (err error) {
|
|||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
s.items[id] = nil
|
||||
delete(s.items, id)
|
||||
|
||||
return
|
||||
|
||||
|
@ -135,7 +135,7 @@ func (s *socket) flush(id string) (err error) {
|
|||
// pending message notifications
|
||||
// for this socket when done.
|
||||
|
||||
s.items[id] = nil
|
||||
delete(s.items, id)
|
||||
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in a new issue