To build on this, i think you can use SQL and triggers to say, IF a INSERT is made into XYZ then count the number and insert the value into another field or table.
https://www.w3resource.com/mysql/mysql-triggers.php
So you can think of it like a PHP version, you tell SQL that IF an insert is run into the forum COUNT the topic and then UPDATE the table you want ?