Optimize db access, fix site prefix issue