4.1.3
This commit is contained in:
@@ -16,21 +16,24 @@ async function ensureGeoData(force = false) {
|
||||
const cities = JSON.parse(fs.readFileSync(path.join(dataDir, 'cities.json'), 'utf8'))
|
||||
|
||||
const provincesWithFaCount = provinces.filter((p) => p.name_fa).length
|
||||
const citiesWithFaCount = cities.filter((c) => c.name_fa).length
|
||||
|
||||
const [countryCount, provinceCount, cityCount, provinceFaCount] = await Promise.all([
|
||||
const [countryCount, provinceCount, cityCount, provinceFaCount, cityFaCount] = await Promise.all([
|
||||
CountryModel.countDocuments(),
|
||||
ProvinceModel.countDocuments(),
|
||||
CityModel.countDocuments(),
|
||||
ProvinceModel.countDocuments({ name_fa: { $exists: true, $ne: null } })
|
||||
ProvinceModel.countDocuments({ name_fa: { $exists: true, $ne: null } }),
|
||||
CityModel.countDocuments({ name_fa: { $exists: true, $ne: null } })
|
||||
])
|
||||
const inSync =
|
||||
countryCount === countries.length &&
|
||||
provinceCount === provinces.length &&
|
||||
cityCount === cities.length &&
|
||||
provinceFaCount === provincesWithFaCount
|
||||
provinceFaCount === provincesWithFaCount &&
|
||||
cityFaCount === citiesWithFaCount
|
||||
if (!force && inSync) return
|
||||
|
||||
console.log(`[boot] Geo reference data out of sync (countries: ${countryCount}/${countries.length}, provinces: ${provinceCount}/${provinces.length}, cities: ${cityCount}/${cities.length}) — reseeding...`)
|
||||
console.log(`[boot] Geo reference data out of sync (countries: ${countryCount}/${countries.length}, provinces: ${provinceCount}/${provinces.length}, cities: ${cityCount}/${cities.length}, city name_fa: ${cityFaCount}/${citiesWithFaCount}) — reseeding...`)
|
||||
|
||||
await CountryModel.deleteMany({})
|
||||
await ProvinceModel.deleteMany({})
|
||||
|
||||
Reference in New Issue
Block a user