Example #1
0
def yieldRevIdGroups(excludeDeletedMeta=True, excludeSingleRevs=True, onlyGroupsPendingSync=True, batch_size=8192):
    LastRevMain = aliased(db.LastRevision, name="last_rev_main")
    LastRevOther = aliased(db.LastRevision, name="last_rev_other")

    q = db.session.query(
        LastRevMain.id.label("main_id"),
        ArraySel(select([LastRevOther.id]).where(LastRevOther.duplicate_of_id == LastRevMain.id)).label("other_revs"),
    ).filter(LastRevMain.duplicate_of_id.is_(None))

    if excludeDeletedMeta:
        q = q.filter(LastRevMain.meta.isnot(None))

    q = q.subquery()
    outerq = db.session.query(q.c.main_id, q.c.other_revs)

    if excludeSingleRevs:
        outerq = outerq.filter(db.func.array_length(q.c.other_revs, 1) > 0)

    if onlyGroupsPendingSync:
        outerq = outerq.filter(
            exists(
                select([1])
                .select_from(join(db.LastRevision, db.Item, db.LastRevision.item_id == db.Item.id))
                .where(db.LastRevision.id == db.func.any(db.func.array_append(q.c.other_revs, q.c.main_id)))
                .where(db.Item.dspace_cur_rev_id.op("is distinct from")(db.LastRevision.id))
            )
        )

    return db.yield_batches(outerq, q.c.main_id, batch_size, id_from_row=lambda row: row[0])
Example #2
0
def yieldNotYetSyncedRevisions(q, **kwargs):
    """
    Percorre batches de last_revision que ainda não tenham sido sincronizados.

    - `q`: query que deve conter um join nas tabelas last_revision e item.
    - `id_from_row`: função para obter o item_id a partir da projeção, caso o
      resultado não esteja sendo coletado em um objeto ORM.
    """
    return db.yield_batches(
        q.filter(
            db.Item.dspace_cur_rev_id.op('is distinct from')(
                db.LastRevision.id)), db.LastRevision.item_id, **kwargs)
Example #3
0
def yieldNotYetSyncedRevisions(q, **kwargs):
    """
    Percorre batches de last_revision que ainda não tenham sido sincronizados.

    - `q`: query que deve conter um join nas tabelas last_revision e item.
    - `id_from_row`: função para obter o item_id a partir da projeção, caso o
      resultado não esteja sendo coletado em um objeto ORM.
    """
    return db.yield_batches(
        q.filter(db.Item.dspace_cur_rev_id.op("is distinct from")(db.LastRevision.id)),
        db.LastRevision.item_id,
        **kwargs
    )
Example #4
0
def yieldRevIdGroups(excludeDeletedMeta=True,
                     excludeSingleRevs=True,
                     onlyGroupsPendingSync=True,
                     batch_size=8192):
    LastRevMain = aliased(db.LastRevision, name='last_rev_main')
    LastRevOther = aliased(db.LastRevision, name='last_rev_other')

    q = db.session.query(LastRevMain.id.label('main_id'),
                         ArraySel(select([LastRevOther.id])
                                  .where(LastRevOther.duplicate_of_id == LastRevMain.id))
                         .label('other_revs'))\
                  .filter(LastRevMain.duplicate_of_id.is_(None))

    if excludeDeletedMeta:
        q = q.filter(LastRevMain.meta.isnot(None))

    q = q.subquery()
    outerq = db.session.query(q.c.main_id, q.c.other_revs)

    if excludeSingleRevs:
        outerq = outerq.filter(db.func.array_length(q.c.other_revs, 1) > 0)

    if onlyGroupsPendingSync:
        outerq = outerq.filter(
            exists(
                select([1]).select_from(
                    join(db.LastRevision, db.Item,
                         db.LastRevision.item_id == db.Item.id)).
                where(db.LastRevision.id == db.func.any(
                    db.func.array_append(q.c.other_revs, q.c.main_id))).where(
                        db.Item.dspace_cur_rev_id.op('is distinct from')(
                            db.LastRevision.id))))

    return db.yield_batches(outerq,
                            q.c.main_id,
                            batch_size,
                            id_from_row=lambda row: row[0])