Forum Discussion

peterlu's avatar
peterlu
Champion
10 years ago

Categories Boards Posts Count - API v2 version

<#assign menuItems = ["CategoryA", "CategoryB", "CategoryC"] />
		

<div class="lia-component-custom-community-browser">
	<div class="panel">
		<ul>
			<#list menuItems as item>
			
			<#-- possible from v1 to v2? 
			
			<#assign category = restadmin("/categories/id/${item}").category />
			<li>
				<span>${category.title?html}</span>
				<ul>
					<#list category.boards.board as board>					
					<#assign count = rest("/boards/id/${board.id}/posts/style/all/count").value?number />
					<li><a href="${board.@view_href}">${board.title?html}</a><span>(${count?string(",##0")})</span></li>
					</#list>
				</ul>
			</li>
			
			-->
			
			</#list>
		</ul>
	</div>
</div>

 My question is:

If each category has 100 boards, my v1 version may need to do at least 300 api calls.

Not sure if there is a v2 version to reduce the number of api calls.

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi peterlu 

     

    I think the real issue here is that you need to get a data point for 300 items. So maybe the problem could be seen in a different way, for example assuming that the board structure does not change often (which is a fair assumption in most scenarios), then you can do your 300 calls once, and cache the result at the application level for a suitable amount of time. 

     

    Thanks,

     

     

     

    • peterlu's avatar
      peterlu
      Champion
      PaoloT Cache will work. I am just curious about the possibility in API v2, since I am going to move my future dev work into v2. This user case has happened to many of my customers, so it is worth to bring it up :)
      • PaoloT's avatar
        PaoloT
        Lithium Alumni (Retired)

        Hi peterlu 

         

        ah I see. A way to do that in an SQL-Like language would be to select a post count by board ID, having a category in the where clause and then grouping by the board ID. I don't think group by is currently available in LiQL - maybe worth pinging JeffY to see if this in in the plans (although I imagine it is a quite sizeable task to add this feature).

         

        In the meantime, you could alway perform the aggregation in your code, having something like (where Cat1 and Cat2 are your categories)

         

        SELECT id,board.id FROM messages WHERE category.id IN ('Cat1','Cat2');

         And then paginate the result, which could be slightly more compact.

         

        Kind Regards,