billcobbler / casbin-redis-watcher

Redis watcher for Casbin https://github.com/casbin/casbin
Apache License 2.0
19 stars 23 forks source link

Avoid redundant callback invocations? #13

Closed erichulburd closed 4 years ago

erichulburd commented 4 years ago

Calling watcher.Update will result in the publishing instances to invoke their callback function . You can test this by running a single node with a watcher, and you'll see the callback function fired after saving a policy.

Is there any easy way out of this inefficiency? I realize this may be an issue for the actual Casbin repository, but I'm wondering if there are any Redis limitations that would prevent improved behavior.

hsluoyz commented 4 years ago

Why do you call Update()? The example to follow is: https://github.com/billcobbler/casbin-redis-watcher#simple-example

Update() is kind of internal function and is not expected to be called by users.

https://github.com/billcobbler/casbin-redis-watcher/blob/c05521d98fa2c9b903d1326b5b25b06ffe20f7ad/watcher.go#L142-L157

billcobbler commented 4 years ago

Hey @erichulburd,

You can easily avoid this by passing the NewWatcher the option IgnoreSelf(true).

https://github.com/billcobbler/casbin-redis-watcher/blob/c05521d98fa2c9b903d1326b5b25b06ffe20f7ad/options.go#L62

erichulburd commented 4 years ago

@hsluoyz I realize that - I was referring to the Update call in SavePolicy

@billcobbler Thanks, exactly what I was looking for.