#include "dbconfigworker.h"
#include "zbx_host_constants.h"
#include "zbxipcservice.h"
#include "zbxcacheconfig.h"
static void dbsync_item_rtname(zbx_vector_uint64_t *hostids, int *processed_num, int *updated_num,
#define ZBX_DBCONFIG_BATCH_SIZE 1000
zbx_dc_um_handle_t *um_handle;
size_t sql_alloc = 0, sql_offset = 0;
size_t sql_select_alloc = 0;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
if (0 == hostids->values[0])
zbx_vector_uint64_remove(hostids, 0);
if (0 == hostids->values_num)
um_handle = zbx_dc_open_user_macros();
zbx_db_begin_multiple_update(&sql, &sql_alloc, &sql_offset);
for (zbx_uint64_t *batch = hostids->values; batch < hostids->values + hostids->values_num;
batch += ZBX_DBCONFIG_BATCH_SIZE)
int batch_size = MIN(ZBX_DBCONFIG_BATCH_SIZE, hostids->values + hostids->values_num - batch);
size_t sql_select_offset = 0;
zbx_strcpy_alloc(&sql_select, &sql_select_alloc, &sql_select_offset,
"select i.itemid,i.hostid,i.name,ir.name_resolved"
" from items i,item_rtname ir"
" where i.name like '%%{$%%' and ir.itemid=i.itemid");
zbx_strcpy_alloc(&sql_select, &sql_select_alloc, &sql_select_offset, " and");
zbx_db_add_condition_alloc(&sql_select, &sql_select_alloc, &sql_select_offset, "i.hostid",
zbx_strcpy_alloc(&sql_select, &sql_select_alloc, &sql_select_offset, " order by i.itemid");
result = zbx_db_select("%s", sql_select);
zabbix_log(LOG_LEVEL_DEBUG, "fetch started");
while (NULL != (row = zbx_db_fetch(result)))
ZBX_STR2UINT64(hostid, row[1]);
name = zbx_strdup(NULL, row[2]);
(void)zbx_dc_expand_user_and_func_macros(um_handle, &name, &hostid, 1, NULL);