Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Using JSON files instead of a database for 1,699 exam paper records

Описание и применение

Использование JSON‑файлов вместо базы данных для 1 699 записей экзаменационных материалов привело к скрытым ошибкам в генерации URL‑адресов, чтении аналитики и одновременной записи. После внедрения проверки коллизий, очереди записи и явной обработки отсутствующих ключей сайт теперь корректно обслуживает все записи и защищён от повреждения файлов.

Задача

Managing 1,699 exam paper records with flat JSON files caused hidden bugs in slug generation, analytics reading, and concurrent writes, leading to unreachable records, broken homepage sections, and data corruption.

Результат

The site now serves all 1,699 exam papers correctly, displays accurate download analytics, and prevents file corruption from concurrent writes. The main limitations are process count and the need for manual index rebuilding.

Рабочий процесс

  • 1. Read entire JSON file with fs.readFileSync and parse it.
  • 2. Generate slugs using a base slug and, if necessary, a code‑qualified suffix to avoid collisions.
  • 3. Build a slug index keyed by file mtime and size to avoid rebuilding on every call.
  • 4. Enqueue write operations via a promise chain to serialize concurrent writes.
  • 5. Write to a temporary file and rename to avoid partial writes.
  • 6. Restore from a backup if JSON parsing fails.
  • 7. Replace silent defaults (|| {}) with explicit error handling for missing keys.

Доказательства

95 papers that existed but had no URL

Источник

Two requests writing the file at once will corrupt it

Источник

  • Дата записи: 2026-09-16T14:30:21.749Z