Repository navigation
Fix: Cache listDesa terus diperpanjang dan tidak membedakan parameter $all - #1811
Merged
Merged
Conversation
… $all
- Tulis cache hanya setelah data diambil dari API agar TTL 24 jam tidak
diperpanjang pada setiap cache hit
- Kunci cache menyertakan kode kecamatan dan parameter $all
(listDesa_{kodeKecamatan}_{all|default})
- Hasil kosong tetap tidak di-cache
- Tambah test regresi TTL, pemisahan $all, dan hasil kosong
Closes #1798
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
habibie11
marked this pull request as ready for review
November 19, 2026 06:29
Contributor
|
🔄 AI PR Review sedang antri di server...
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
issue #1798
🎯 Deskripsi
Pada mode Database Gabungan,
DesaService::listDesa()punya dua masalah cache:Cache::put('listDesa', ...)dijalankan setiap kali data tidak kosong, termasuk saat data berasal dari cache. Setiap request memulai ulang TTL 24 jam, sehingga selama ada trafik rutin, desa yang ditambah atau diubah di server gabungan tidak pernah muncul.$alldiabaikan. Kunci cache statis'listDesa'dipakai untuklistDesa(false)danlistDesa(true). Siapa pun yang mengisi cache lebih dulu menentukan hasil untuk keduanya. Contohnya, ekspor Data Desa (listDesa(true)) bisa menerima daftar milik navbar (listDesa(false)).Solusi:
Cache::puthanya dijalankan setelah data diambil dari API, sehingga cache kedaluwarsa tepat 24 jam setelah pengambilan.listDesaCacheKey(bool $all)dengan formatlistDesa_{kodeKecamatan}_{all|default}.Cache::remembersengaja tidak dipakai karena akan ikut menyimpan collection kosong selama 24 jam.Mode lokal (
DataDesa::all()), signature method, dan bentuk data yang dikembalikan tidak berubah.🛠️ Perubahan yang Dilakukan
1.
app/Services/DesaService.phpFix — Cache hanya ditulis saat cache miss, kunci memperhitungkan kecamatan dan
$all:2.
tests/Unit/Services/DesaServiceTest.phpTest — Regresi untuk TTL, pemisahan
$all, dan hasil kosong:tidak memperpanjang ttl cache saat cache hit: panggilan pertama ke API, setelah 23 jam masih dari cache, dan setelah total 25 jam harus ada request API ke-2.memisahkan cache berdasarkan parameter all:listDesa(false)danlistDesa(true)mendapat data masing-masing dan tidak saling menimpa.tidak menyimpan hasil kosong ke cache.menyertakan kode kecamatan dan parameter all pada kunci cache.'listDesa'langsung kini memakailistDesaCacheKey().Tiga test perilaku di atas gagal pada logika lama dan lulus setelah perbaikan.
3.
tests/Feature/ExportDatabaseGabunganTest.phpTest — Menyesuaikan kunci cache:
Cache::put('listDesa', ...)digantiCache::put((new DesaService())->listDesaCacheKey(), ...).✅ Test Cases yang Diimplementasikan
listDesa(false)danlistDesa(true)memakai kunci cache terpisahall/defaultDesaServiceTest,ExportDatabaseGabunganTest, danSuplemenGabunganTesttetap lulus (64 passed)📸 Cara Menjalankan Uji Coba Manual
Semua URL di bawah relatif terhadap base URL aplikasi (misalnya
http://opendk.test). Login sebagai admin (/login). Database Gabungan harus aktif melalui sidebar Pengaturan → Aplikasi (/setting/aplikasi) dengansinkronisasi_database_gabungan = 1dan server API yang valid.php artisan cache:clear, lalu buka sidebar Data → Kecamatan → Data Desa (/data/data-desa). Nama sub-grup "Kecamatan" mengikuti sebutan wilayah.listDesa_<kodekecamatan>_default./data/data-desa/export-excel).all), bukan salinan cache variandefault. Di cache terbentuk kuncilistDesa_<kodekecamatan>_all./data/data-sarana) dan periksa dropdown filter desa.listDesa()default).php artisan tinkerlaluCache::forget((new App\Services\DesaService)->listDesaCacheKey()), dan muat ulang/data/data-desa.listDesaselalu diperpanjang.php artisan cache:clear, lalu buka/data/data-desa.🤖 Cara Menjalankan Uji Coba Otomatis (Automated Test)
📸 Screenshot atau Video
[isi foto atau video]
🤖 Generated with Claude Code