如何持续“移动”数据库中的纬度/经度对?
我正在设计一个项目,我将在数据库中存储(可能数十万个)纬度/经度对。这些对与其他数据相关联。问题是,除了用户操纵这些数据之外,我还希望位置随着时间的推移而改变。我最初的本能是设置一个 cron 作业,每天将每个纬度/经度调整一定量,但我意识到这样的操作效率极低。
那么,关于如何随着时间的推移有效调整一堆纬度/经度对有什么想法吗?到目前为止,我最好的想法是将“最后更改”时间戳与每对关联起来,并运行一个进程,每隔几秒触发一次,抓取具有最旧时间戳的 n 个(可能是 100?1000?)对,调整这些对并更新时间。通过这种方式,我可以不断地移动少量数据,而不是每天一次移动大量数据。不过,我仍然不相信这是最好的方法。
提前致谢!
I'm designing a project where I'll be storing (potentially hundreds of thousands of) lat/lon pairs in a database. The pairs are associated with other data. The catch is that in addition to users manipulating this data, I also want the locations to change over time. My initial instinct was to set up a cron job that will adjust every lat/lon by a certain amount every day, but I realize that such an operation would be insanely inefficient.
So, any ideas on how to efficiently adjust a bunch of lat/lon pairs over time? My best thought so far is associating a "last changed" timestamp with each pair and have a process running that fires every few seconds, grabs n (maybe order 100? 1000?) pairs with the oldest timestamps, adjusts those pairs and updates the times. This way I'm constantly moving small amounts of data, instead of moving an overwhelming amount once a day. I'm still not convinced this is the best way to go, though.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将添加到每对的金额存储在其他地方,而不是直接使用数据库中的值,而是在检索时添加此存储的偏移量,并在插入时减去它。
Store the amount that is added to each pair somewhere else, and rather than using the values in the database directly, add this stored offset amount whenever you retrieve and subtract it whenever you insert.
你的直觉是对的,这可能是逐渐调整经纬度的最佳方法。不过,更新查询不应该对服务器造成太大的影响,并且您不会移动 - 只是更改?
Your instinct is right, that probably is the best way of adjusting latitude longitude gradually. The update query shouldn't hammer the server too hard though, and your not moving- Just changing?