I have an android application that helps in doctor appointments. On one side, the concerned doctor adds slots in the mobile application on the other side users searches for the dr, his/her profile, and the number of slots available. The user then books a particular slot for consultancy. The slot is then removed/designated as booked. Ideally the slot should not be viewed by the next user. The entire database is in Firebase Realtime Database.
This is how I am accessing the data from Firebase in android (Since this is a very large code, I am showing only the relevant portions):
ref3 = drRef.orderByChild("Dr Name").startAt(drNameTemp).endAt(drNameTemp+"uf8ff")
ref3.keepSynced(true)
//There could be multiple doctors with same name and each doctor can have multiple chambers. Hence a loop. The user sees the image and profile to select the doctor he/she requires. There is a nesting in here
listener = ref3.addValueEventListener(object: ValueEventListener {
override fun onDataChange(p0: DataSnapshot) {
for (uniqueKeySnapshot in p0.children) {
val drBook = TextView(this@Doctor)
bookingLayout.addView(drBook) //This is the layout on which each doctor profile is being displayed
drBook.setOnClickListener {
for (drKeySnapshot in p0.child(querykey).child("ChamberAddress").children) {
val chamberkey = drKeySnapshot.key
if(chamberkey!=null){
var tuesdayslots = p0.child(querykey).child("ChamberAddress").child(chamberkey).child("TuesdaySlots.getValue(Long::class.java)")
}
}
}
}
}
})
The value of tuesdayslots is displayed to the user, which is basically the number of slots remaining for the day for that particular chamber. Now when a user books one slot, the database correctly reduces one slot (This is handled in cloud function and works perfectly).
The issue is that, when the next user comes to book, on the first search he/she sees some old value in the display. This value is usually same as the value he/she saw when she last searched for this doctor. Possibly the system had cached this value. The value updates itself only on a second search.
I have used ref3.keepSynced(true) hoping that this problem would not arise. But that does not work. What is possibly going wrong over here.
Since I have given only the required structure of the search, if any further information/code is needed, I would be happy to share.