Created
November 1, 2013 11:02
-
-
Save jorgeuriarte/7263920 to your computer and use it in GitHub Desktop.
Dos implementaciones diferentes del mismo método hechas por dos personas, intentando optimizar las conexiones a redis. Resulta que al final lo hicimos casi igual :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String generarSitemapCategorias(categoria) { | |
def categorias = [] as Set | |
def descendientes = this.redisInstance.zrange( "categoria:${categoria}:descendientes", 0, -1) | |
def categoriasYEventos = [:] | |
this.redisInstance.withPipeline { pipe -> | |
categoriasYEventos = descendientes.findResults { | |
[id: it, zcard: pipe.zcard("categoria:${it}:eventos")] | |
} | |
} | |
categorias = categoriasYEventos.findResults { if (it.zcard.get() > 0) it.id } | |
return generarSitemap(categorias, "categoria", "categoriaSinPage") | |
} | |
public String generarSitemapCategorias(categoria) { | |
def categorias = [] | |
def descendientes = this.redisInstance.zrange( "categoria:${categoria}:descendientes", 0, -1); | |
def categoriasEventos = [] | |
redisInstance.withPipeline { pipe -> | |
categoriasEventos = descendientes.findResults { | |
[id: it, eventosDescendientes: pipe.zcard("categoria:${it}:eventos")] | |
} | |
} | |
categoriasEventos.each{ | |
if (it.eventosDescendientes.get()) { | |
categorias << it.id | |
} | |
} | |
return generarSitemap(categorias, "categoria", "categoriaSinPage") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment