Optimize template update
Analogue to literature lists, this MR optimizes the update process of templates by storing the relevant statements of the template within the update state, eliminating the need to query the database over and over again for the required statements. Although there is a large number of changed files, the changes are very simple when going through individual commits.