Fix calculation of direct entries count.

Will re-calculate the direct entries count in each save to avoid
situation where two saves are made simultaneously causing race condition
and wrong value save to the DB.