mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-26 14:27:14 +00:00
devicestate: Don't publish redundant device state messages.
When publishing device state check the local cache for the existing device state. If the new device state is unchanged from the prior one, don't bother publishing the update. This can reduce the work done by consumers of device state, such as hints and app_queue, by not publishing a message to them. These messages would most often occur with devices that are seeing numerous simultaneous channels. The underlying device state would remain as in use throughout, but an update would be published as channels are created and hung up.
This commit is contained in:
@@ -309,14 +309,14 @@ enum ast_device_state ast_parse_device_state(const char *device)
|
||||
return res;
|
||||
}
|
||||
|
||||
static enum ast_device_state devstate_cached(const char *device)
|
||||
static enum ast_device_state devstate_cached(const char *device, const struct ast_eid *eid)
|
||||
{
|
||||
struct stasis_message *cached_msg;
|
||||
struct ast_device_state_message *device_state;
|
||||
enum ast_device_state state;
|
||||
|
||||
cached_msg = stasis_cache_get_by_eid(ast_device_state_cache(),
|
||||
ast_device_state_message_type(), device, NULL);
|
||||
ast_device_state_message_type(), device, eid);
|
||||
if (!cached_msg) {
|
||||
return AST_DEVICE_UNKNOWN;
|
||||
}
|
||||
@@ -338,7 +338,7 @@ static enum ast_device_state _ast_device_state(const char *device, int check_cac
|
||||
|
||||
/* If the last known state is cached, just return that */
|
||||
if (check_cache) {
|
||||
res = devstate_cached(device);
|
||||
res = devstate_cached(device, NULL);
|
||||
if (res != AST_DEVICE_UNKNOWN) {
|
||||
return res;
|
||||
}
|
||||
@@ -725,6 +725,16 @@ int ast_publish_device_state_full(
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cachable) {
|
||||
enum ast_device_state res;
|
||||
|
||||
/* If the state is unchanged, do not publish */
|
||||
res = devstate_cached(device, eid);
|
||||
if (res == state) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
device_state = device_state_alloc(device, state, cachable, eid);
|
||||
if (!device_state) {
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user