update db function

reduce sql query. only require when needed