# API improvment : nb\_notes per folder/tag

**URL:** <https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820>\
**Category:** Features\
**Created:** [29 June 2019 15:47 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820 "2019-06-29T15:47:06Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![foxmask](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@foxmask](https://discourse.joplinapp.org/u/foxmask)\
**Post date:** [29 June 2019 15:47 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/1 "2019-06-29T15:47:06Z")

</div>

Could it be possible to improve the API and return the number of notes per folder or tag ?

currently I have to do

```auto
GET /folders

```

and for each item

```auto
GET /folders/:id/notes

```

and repeat it for each sub folder

plus the same with tags

```auto
GET /tags/:id/notes

```

but it's time consumming 😕

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [29 June 2019 23:03 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/2 "2019-06-29T23:03:25Z")

</div>

In that case, I’d suggest to add `/count` at the end to retrieve the number.

---

<div class="post-metadata">

**Author:** ![foxmask](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@foxmask](https://discourse.joplinapp.org/u/foxmask)\
**Post date:** [29 June 2019 23:23 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/3 "2019-06-29T23:23:48Z")

</div>

That does not solve th Iproblem of one request too much  
I really need the count of notes per tag or folder when i get that info of each of them

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [29 June 2019 23:35 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/4 "2019-06-29T23:35:34Z")

</div>

Ah, I see.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [30 June 2019 00:14 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/5 "2019-06-30T00:14:21Z")

</div>

I guess we could have a note\_count property on the tag and folder objects. It would be a virtual property (since not in the db) calculated dynamically when requesting the object.

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [30 June 2019 02:36 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/6 "2019-06-30T02:36:08Z")

</div>

Could either of you provide an API endpoint example for this functionality?

---

<div class="post-metadata">

**Author:** ![foxmask](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@foxmask](https://discourse.joplinapp.org/u/foxmask)\
**Post date:** [30 June 2019 07:09 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/7 "2019-06-30T07:09:59Z")

</div>

It should not be a new endpoint, it should be available with

```auto
/GET tags
/GET tag
/GET folders
/GET folder

```

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [30 June 2019 18:54 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/8 "2019-06-30T18:54:03Z")

</div>

So you would like the API to return something like this for `GET /folders`:

```auto
  {
    "id": "140a30783e5d4b00819ba878f792dd23",
    "parent_id": "",
    "title": "My Test Folder",
    "notes_count": 17,
    "type_": 2
  },
...

```

---

<div class="post-metadata">

**Author:** ![foxmask](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@foxmask](https://discourse.joplinapp.org/u/foxmask)\
**Post date:** [30 June 2019 19:35 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/9 "2019-06-30T19:35:39Z")

</div>

yes 🙂  
With the process I discribed in post 1 , I added notes\_count by myself after having queried `/folders/:id/notes` which is absolutly not good for perf.

---

<div class="post-metadata">

**Author:** ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)\
**Post date:** [30 June 2019 20:53 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/10 "2019-06-30T20:53:10Z")

</div>

Yes that’s correct. As the “notes\_count” property is not in the database, it would be a virtual one that’s computed when you request it. We don’t really have this concept in the API now but it’s a useful one and shouldn’t be too hard to add.

---

<div class="post-metadata">

**Author:** ![tessus](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/tessus/32/13_2.png) [@tessus](https://discourse.joplinapp.org/u/tessus)\
**Post date:** [1 July 2019 03:16 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/11 "2019-07-01T03:16:41Z")

</div>

> [@foxmask](#):
>
> which is absolutly not good for perf.

Although, when you look at the server side of things, that value has to be calculated for every folder, thus an additional `count(*)` statement (which requires a table scan - very bad for perf) has to be executed. Thus the runtime changes from O(N) to O(N\*M). M is the average number of notes per folder.

I'm not convinced that such an edge case warrants the perf impact for everything else. But hey, I'm not the owner, so it's not my call. Such an impact is only acceptable, when requested (by a flag, endpoint alteration, ...) and should not be done by default. I've been a long time in performance and I'm just saying that you should be aware of the consequences. It might not matter if you have a few notes, but it will be noticeable, if you have a a lot of notes and folders.

So the overhead you have experiennced when doing it manually, will now be done by the server - every time someone request a list of folders.

---

<div class="post-metadata">

**Author:** ![foxmask](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@foxmask](https://discourse.joplinapp.org/u/foxmask)\
**Post date:** [1 July 2019 05:12 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/12 "2019-07-01T05:12:24Z")

</div>

I know all of That.  
Would be better if the counter was a real column that is increased or decreased each time a post or delete occured  
No?

---

<div class="post-metadata">

**Author:** ![sciurius](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/sciurius/32/132_2.png) [@sciurius](https://discourse.joplinapp.org/u/sciurius)\
**Post date:** [1 July 2019 06:28 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/13 "2019-07-01T06:28:58Z")

</div>

It duplicates information. And, as the saying goes, “If you have two copies of the same information, at least one of them is wrong.”

---

<div class="post-metadata">

**Author:** ![foxmask](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@foxmask](https://discourse.joplinapp.org/u/foxmask)\
**Post date:** [1 July 2019 09:08 UTC](https://discourse.joplinapp.org/t/api-improvment-nb-notes-per-folder-tag/2820/14 "2019-07-01T09:08:33Z")

</div>

yes, at least if what suggested laurent could see the light, that should be helpful
