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

Tweaks to # of maps shown on front page, per "region" #834

Closed
3 tasks done
jywarren opened this issue Jul 10, 2019 · 1 comment · Fixed by #879
Closed
3 tasks done

Tweaks to # of maps shown on front page, per "region" #834

jywarren opened this issue Jul 10, 2019 · 1 comment · Fixed by #879

Comments

@jywarren
Copy link
Member

jywarren commented Jul 10, 2019

The "regions" code here fulfills requests from the front page map (and other types of requests):

# list by region
def region
area = params[:id] || 'this area'
@title = "Maps in #{area}"
ids = Map.bbox(params[:minlat], params[:minlon], params[:maxlat], params[:maxlon]).collect(&:id)
@maps = Map.where(password: '')
.where('id IN (?)', ids)
.paginate(page: params[:page], per_page: 24)
.except(:styles, :email)
@maps.each do |map|
map.image_urls = map.warpables.map { |warpable| warpable.image.url }
end
respond_to do |format|
format.html { render 'maps/index', layout: 'application' }
format.json { render json: @maps.to_json(methods: :image_urls) }
end
end

It's accessed in JSON via:

https://mapknitter.org/map/region/Gulf-Coast.json?minlon=16.017661392688755&minlat=12.539611262767895&maxlon=158.22469264268878&maxlat=67.19809660495382

(for example)

Actually, Gulf-Coast is not needed, it can be any name:

https://mapknitter.org/map/region/region.json?minlon=16.01&minlat=12.53&maxlon=158.22&maxlat=67.19

Let's do 2 things:

  • increase the number of maps to... 50?
  • cache these daily, using the technique below, to speed up response time, esp. for "featured" regions.
  • the "regions" route there seems like it could be modified to include a tag parameter to filter for maps with a tag!
Rails.cache.fetch("some-unique-cache-key", expires_in: 1.day) do
  # code to be cached wrapped here
end

number of map code would be:

               .paginate(page: params[:page], per_page: 24)

cc @ebarry

@jywarren
Copy link
Member Author

jywarren commented Jul 10, 2019

There could be potential for trimming the results for efficiency too, but let's think about that later!

{"id":67,"name":"qalandia","lat":"31.8704553147","lon":"35.2206727512","version":1,"password":"","styles":"VERY_LONG_STRING","created_at":"2010-06-25T10:36:58.000Z","updated_at":"2014-11-13T19:22:11.000Z","description":null,"author":"anonymous","zoom":"16.0","location":"Qalandia","static_data":"","vectors":false,"tiles":"google","email":"","archived":false,"tile_url":"","tile_layer":"","license":"copyright","user_id":0,"anon_annotatable":false,"slug":"qalandia","image_urls":["https://s3.amazonaws.com/grassrootsmapping/warpables/625/kafr_aqb.png"]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants