In get_children method is performed recursive call of the class method. So you must do the check in method, which level was clicked. Also in the code sample of the blog, that you mentioned, is done the check. So you have to do the check and eliminate the processing of same entity again.
It is all up to the coding, so you have all the freedom.
Best regards, Robert