# Find\_next() being called twice with same kp and type {same\_or\_next}

**URL:** <https://dmap-community.ductus.global/t/find-next-being-called-twice-with-same-kp-and-type-same-or-next/3615>\
**Category:** Core Engine and APIs\
**Created:** [April 26, 2021, 10:49am UTC](https://dmap-community.ductus.global/t/find-next-being-called-twice-with-same-kp-and-type-same-or-next/3615 "2021-04-26T10:49:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdf](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@sdf](https://dmap-community.ductus.global/u/sdf)\
**Post date:** [April 26, 2021, 10:49am UTC](https://dmap-community.ductus.global/t/find-next-being-called-twice-with-same-kp-and-type-same-or-next/3615/1 "2021-04-26T10:49:04Z")

</div>

Hi,

I tried the examples in dp/find\_next.  
When get the ports by CLI, find\_next() callback is called twice. Why is that? What’s the different between them?

CLI command:

> # show port 4 \*
> 
> ## SLOT PORT STATUS
> 
> 4 0 error  
> 4 2 disabled

callbacks log:

> TRACE New user session: 14 for user:admin ctx:cli → CONFD\_OK  
> TRACE CALL trans init(thandle=12,mode=“r”,db=running) → CONFD\_OK  
> TRACE CALL data **find\_next(thandle=12, /port, same\_or\_next, {4})** → CONFD\_OK  
> TRACE CALL data **find\_next(thandle=12, /port, same\_or\_next, {4})** → CONFD\_OK  
> TRACE CALL data get\_elem(thandle=12,/port{4 0}/status) (enum\<2\>) → CONFD\_OK  
> TRACE CALL data get\_next(thandle=12, /port, 6) → CONFD\_OK  
> TRACE CALL data get\_elem(thandle=12,/port{4 2}/status) (enum\<0\>) → CONFD\_OK  
> TRACE CALL data get\_next(thandle=12, /port, 7) → CONFD\_OK  
> TRACE NULL trans finish(thandle=12)  
> TRACE Close user sess 14  
> → CONFD\_OK

When use netconf command, find\_next() callback is called once, as below:

> netconf-console --get -x ‘/port[slot=4]/status’

callbacks log:

> TRACE New user session: 17 for user:admin ctx:netconf → CONFD\_OK  
> TRACE CALL trans init(thandle=14,mode=“r”,db=running) → CONFD\_OK  
> TRACE CALL data **find\_next(thandle=14, /port, same\_or\_next, {4})** → CONFD\_OK  
> TRACE CALL data get\_next(thandle=14, /port, 6) → CONFD\_OK  
> TRACE CALL data get\_next(thandle=14, /port, 7) → CONFD\_OK  
> TRACE CALL data get\_elem(thandle=14,/port{4 0}/status) (enum\<2\>) → CONFD\_OK  
> TRACE CALL data get\_elem(thandle=14,/port{4 2}/status) (enum\<0\>) → CONFD\_OK  
> TRACE NULL trans finish(thandle=14)  
> TRACE Close user sess 17  
> → CONFD\_OK

Thanks!

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [April 26, 2021, 12:56pm UTC](https://dmap-community.ductus.global/t/find-next-being-called-twice-with-same-kp-and-type-same-or-next/3615/2 "2021-04-26T12:56:17Z")

</div>

Hi,

The CLI is a human-to-machine interface so ConfD must fetch things like tab-complete, table look-ahead, etc. data.

---

<div class="post-metadata">

**Author:** ![sdf](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@sdf](https://dmap-community.ductus.global/u/sdf)\
**Post date:** [April 26, 2021, 1:49pm UTC](https://dmap-community.ductus.global/t/find-next-being-called-twice-with-same-kp-and-type-same-or-next/3615/3 "2021-04-26T13:49:13Z")

</div>

Hi,

If so, how to reply to these find\_next() callbacks? Especially when the list with lots of items and performance need to be considered. Is there a general way to handle this?

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [April 26, 2021, 3:36pm UTC](https://dmap-community.ductus.global/t/find-next-being-called-twice-with-same-kp-and-type-same-or-next/3615/4 "2021-04-26T15:36:04Z")

</div>

If performance is of concern, I suggest you focus on the get\_elem()/get\_next() calls that occur for each list entry, and not the first two find\_next() (that will not be called for each list entry) when you show the data from the CLI.

To avoid get\_elem()/get\_next() calls for each list entry you can also implement find\_next\_object(). In addition, find\_next\_object() will be the only callback called and will only be called once for the use case you describe here. See [https://github.com/ConfD-Developer/ConfD-Demos/tree/master/dp-performance](https://github.com/ConfD-Developer/ConfD-Demos/tree/master/dp-performance) for a demo.

---

<div class="post-metadata">

**Author:** ![sdf](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@sdf](https://dmap-community.ductus.global/u/sdf)\
**Post date:** [April 27, 2021, 11:48am UTC](https://dmap-community.ductus.global/t/find-next-being-called-twice-with-same-kp-and-type-same-or-next/3615/5 "2021-04-27T11:48:11Z")

</div>

Hi,

I did some test on find\_next\_object() callbacks. it’s same as find\_next(), being called twice. In my code, confd\_data\_reply\_next\_object\_tag\_value\_arrays() is used to reply each find\_next\_object() callback including all list items and an end-of-list indication. These two callbacks contains different traversal\_id.

Is it correct?

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [April 27, 2021, 4:59pm UTC](https://dmap-community.ductus.global/t/find-next-being-called-twice-with-same-kp-and-type-same-or-next/3615/6 "2021-04-27T16:59:44Z")

</div>

Yes, they will be called twice.  
However, there will be no get\_elem()/get\_next() calls if you skip registering them as the demo I pointed you to show.  
There is no need for keeping track of any traversal id if you skip get\_next() and register find\_next() + find\_next\_object() only as the demo show as well.
