htmly icon indicating copy to clipboard operation
htmly copied to clipboard

Remove redundant counters and optimize loops

Open mikemastercorp opened this issue 7 months ago • 3 comments

Just found your tiny CMS and liked the performance so decided to look under the hood and thought I can pay back my 5 cents on a few code improvements to remove unnecessary counter variables and provide some code improvements.

mikemastercorp avatar May 26 '25 17:05 mikemastercorp

Having that said, the original code would definitely work as is, it is just as small improvement in terms of readability and habits of PHP Devs to use $key => $value in for() loops. Besides that, I've added a few checks to prevent unnecessary loops where a break was needed where an if() criteria is not met... Like I said, Share-ing is Care-ing ;)

mikemastercorp avatar May 26 '25 19:05 mikemastercorp

Hello,

Thanks for the PR. Yes, it is quite old code indeed, and there are many functions that need to be refactored. Let's try to improve it in the future.

I already reviewed it. There is one problem, so when the contents of views.json are empty or the file does not exist, it takes some of the latest posts. It should display: <ul><li>No popular posts found</li></ul>

danpros avatar May 27 '25 11:05 danpros

I will have a look, maybe I overdid some parts as I am not 100% sure how to test all functions and it might have slipped through. If you have any idea on the method responsible for it, it will speed the things up as I've touched a few and have to dig a bit deeper now :)

mikemastercorp avatar May 29 '25 19:05 mikemastercorp