It is not very optimised for posts that contains multiple tags of this kind. Even less so when multiple tags all refer to the same discussion. It would be good first aggregate all the discussion ids to be able to fetch all available discussion in a single DB query.
Then, at replacement time, if the discussion is not in the fetched collection, when can mark it as unknown.
This is also a good opportunity to refactor the code to parse the XML only once and make the replacements in the resulting DOM instead of parsing it 3 times with Utils::replaceAttributes().
Currently the Renderer makes 1 DB query for each
CROSSREFERENCE*
tag in the post. https://github.com/club-1/flarum-ext-cross-references/blob/152437db44471e500930d9f570f9cbed58ea7ae0/src/Formatter/CrossReferencesRenderer.php#L69-L97It is not very optimised for posts that contains multiple tags of this kind. Even less so when multiple tags all refer to the same discussion. It would be good first aggregate all the discussion ids to be able to fetch all available discussion in a single DB query. Then, at replacement time, if the discussion is not in the fetched collection, when can mark it as
unknown
.This is also a good opportunity to refactor the code to parse the XML only once and make the replacements in the resulting DOM instead of parsing it 3 times with
Utils::replaceAttributes()
.