Instead of searching all entitles for water ghosts every time the mod updates, store water ghosts in a table in global and use that table when processing.
Add water ghosts to this table trough events like on_built_entity or script_raised_built or any other possible build events. Scan for water ghosts entities when initializing the global table, and maybe do infrequent scans refilling the table, if there are any issues regarding water ghost entities not ending up in the table.
Instead of searching all entitles for water ghosts every time the mod updates, store water ghosts in a table in global and use that table when processing. Add water ghosts to this table trough events like on_built_entity or script_raised_built or any other possible build events. Scan for water ghosts entities when initializing the global table, and maybe do infrequent scans refilling the table, if there are any issues regarding water ghost entities not ending up in the table.