
This should greatly reduce the number of unecessary sync calls by storing the last time a gertty queried for changes to a project. Previously, we used the updated time of the latest change in a project, however, subsequent queries with that value would typically return the same change even though it needn't be synced. Adjusting that value by a small amount is unlikely to work reliably because the query is for a relative time and it takes some time to process. Adjusting for a larger amount (eg, a few seconds) might miss data. Clock skew is also a concern in this system because we are using subtracting the server time from the client's time. By storing the last sync time locally, we can continue to update it past the highest value that gerrit has, so that we eventually get queries which return no results. Clock skew is not an issue because the delta arithmetic only involves client generated times. We can also increase the window slightly to account for query processing time without continuously sync already-synced changes. Change-Id: I8cd0af9bd4d3669f436f169059e4b602d4d3036c
34 lines
980 B
Python
34 lines
980 B
Python
"""Added project updated column
|
|
|
|
Revision ID: 38104b4c1b84
|
|
Revises: 56e48a4a064a
|
|
Create Date: 2014-05-31 06:52:12.452205
|
|
|
|
"""
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '38104b4c1b84'
|
|
down_revision = '56e48a4a064a'
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
def upgrade():
|
|
op.add_column('project', sa.Column('updated', sa.DateTime))
|
|
|
|
conn = op.get_bind()
|
|
res = conn.execute("select key, name from project")
|
|
for (key, name) in res.fetchall():
|
|
q = sa.text("select max(updated) from change where project_key=:key")
|
|
res = conn.execute(q, key=key)
|
|
for (updated,) in res.fetchall():
|
|
q = sa.text("update project set updated=:updated where key=:key")
|
|
conn.execute(q, key=key, updated=updated)
|
|
|
|
op.create_index(op.f('ix_project_updated'), 'project', ['updated'], unique=False)
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_project_updated'), table_name='project')
|
|
op.drop_column('project', 'updated')
|