Optimized the database selflink lookup