Performance improvements for the code that fills in artefact.path

Bug 1400524: On a large site, the database queries to retrieve
all records from the artefact table can take too long to execute
and cause the PHP script to time out.

This optimization attempts to fix that by separately handling
the simpler case of parentless artefacts, and by removing
a redundant "select * from artefact"

Change-Id: Iddcfea3161fbfe804ec808119fe771757e7cdd5e