-
-
Save tribals/e29bf18f9ff71758e5c66b9a22c6177d to your computer and use it in GitHub Desktop.
Task
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
""" | |
В таблице 'orders' находится 15млн записей. Необходимо проверить все заказы в статусе 'hold' пачками по 100шт. | |
Статус заказа проверяется в функции 'mark_random_orders_accepted', эта функция ставит рандомное кол-во заказов | |
в статус 'accepted', т.е. '1'. Кол-во, переведенных в статус 'accepted' заказов неизвестно. | |
Необходимо написать оптимальное решение. Нельзя выгружать все заказы в память(вызов .all() в SQLAlchemy). | |
""" | |
class Order(Base): | |
__tablename__ = 'orders' | |
id = Column(BigInteger, nullable=False, primary_key=True, autoincrement=True) | |
name = Column(Unicode, nullable=False) | |
state = Column(Integer, nullable=False, index=True) # accepted = 1, hold = 0 | |
def mark_random_orders_accepted(orders): | |
pass | |
# db setup code, ommited | |
CHUNK_SIZE = 100 | |
for chunk in session.query(Order).filter_by(state=0).yield_per(CHUNK_SIZE): | |
mark_random_orders_accepted(chunk) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment