Last active
August 29, 2015 14:16
-
-
Save jaturken/a70fe33164e3b9086e41 to your computer and use it in GitHub Desktop.
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
# For given shop, category, competitor shop, old&new prefixes and prefix shop: | |
# - find urls for category products competitors(by competitorshop_id) | |
# - generate urls with new prefixes(often 'html' -> 'html?prefix=PR') | |
# - add urls with prefixes to tasks | |
# All in one SQL request. Be careful while debugging, young padawan. | |
# example: shop_id 11245, category_id 1318231, competitorshop_id 12933, | |
# old_prefix 'pr=Q49', new_prefix 'pr=Q51', prefixshop_id 1390 | |
def fill_prefix_shop_for_competitor(shop_id, category_id, competitorshop_id, old_prefix, new_prefix, prefixshop_id, force = false) | |
Db.session do |db| | |
query =<<-SQL | |
INSERT INTO tasks(shop_id, type, param1) | |
SELECT #{prefixshop_id}, 'PRODUCT2TODO', REPLACE(url, | |
'#{old_prefix}', | |
'#{new_prefix}' | |
) | |
FROM locations l | |
INNER JOIN mapping m ON l.product_id = m.competitorprod_id | |
INNER JOIN tags t ON t.product_id = m.product_id | |
WHERE t.tag_id = #{category_id} | |
AND m.shop_id = #{shop_id} | |
AND m.competitorshop_id = #{competitorshop_id} | |
AND m.type IN ('EXACT', 'LFL') | |
and l.url like '%#{old_prefix}%' | |
SQL | |
log query, YELLOW | |
if to_bool(force) | |
log 'Execute request', YELLOW | |
db.do(query) | |
else | |
log "Request not executed without force", YELLOW | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment