Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migration to support z16 metatiling #543

Merged
merged 1 commit into from
Feb 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions data/migrations/v0.8.0-adjust-toi-for-z16-metatiling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from redis import StrictRedis
from tilequeue.cache import RedisCacheIndex
from tilequeue.config import make_config_from_argparse
from tilequeue.tile import coord_marshall_int
from tilequeue.tile import coord_unmarshall_int
import sys

if len(sys.argv) > 1:
cfg_path = sys.argv[1]
else:
cfg_path = '/etc/tilequeue/config.yaml'

cfg = make_config_from_argparse(cfg_path)
redis_client = StrictRedis(cfg.redis_host)
cache_index = RedisCacheIndex(redis_client)
tiles_of_interest = cache_index.fetch_tiles_of_interest()

coord_ints_to_add = set()
for coord_int in tiles_of_interest:
coord = coord_unmarshall_int(coord_int)
if coord.zoom > 16:
coord_at_z16 = coord.zoomTo(16).container()
coord_int_at_z16 = coord_marshall_int(coord_at_z16)
coord_ints_to_add.add(coord_int_at_z16)

batch_size = 100
buf = []
for coord_int in coord_ints_to_add:
buf.append(coord_int)
if len(buf) >= batch_size:
redis_client.sadd(cache_index.cache_set_key, *buf)
del buf[:]
if buf:
redis_client.sadd(cache_index.cache_set_key, *buf)