https://kotlinlang.org logo
#exposed
Title
# exposed
t

tapac

12/24/2017, 6:57 PM
@wouterdoeland, Why do you need to cache it? In which use-case you want to wark with cache?
w

wouterdoeland

12/24/2017, 8:51 PM
50^2*20*n calls per second to the database slows down the application a lot for a certain function
t

tapac

12/24/2017, 11:16 PM
If you use dao, then there is entity cache binded to transaction. Could you provide sample code where you get a lot of excessive queries?
w

wouterdoeland

12/25/2017, 1:18 PM
Copy code
for(x in baseX-regionParticleRange..baseX+regionParticleRange) {
                    for(z in baseZ-regionParticleRange..baseZ+regionParticleRange) {
                        if(regionForWand.inRegion(x, z)) {
                            if(regionForWand.getLocation(x, z) != null) {
                                event.player.spawnParticle(Particle.SNOWBALL, x.toDouble(), baseY.toDouble(), z.toDouble(), 3)
                            }
                            event.player.spawnParticle(Particle.VILLAGER_HAPPY, x.toDouble(), baseY.toDouble(), z.toDouble(), 1)
                        } else {
                            event.player.spawnParticle(Particle.SPELL_WITCH, x.toDouble(), baseY.toDouble(), z.toDouble(), 1)
                        }
                    }
                }
The
regionForWand.inRegion
function will be called a lot. This functions will in turn get a list of all the
Location
objects and will determine whether the requested point is inside these locations. This will make a lot of requests of course as every point calls the
inRegion
function. Maybe I can fix it by creating a new function for inRegion that accepts an array and returns an array with all the points that are inside the locations.
Okay that seems to work
t

tapac

12/25/2017, 1:49 PM
I guess that loading all data about region in single query and test it in memory will be much more effective, b/c every request to db will add delay to send/read data + you may block table for whole transaction.
w

wouterdoeland

12/25/2017, 2:00 PM
yep, that's exactly what happened. So now I'm loading the data once and checking the locations in-memory with that data. Works perfectly now.
🤘 1