gws.plugin.qfieldcloud.delta

Storage of the deltas sent by QField, with their status.

Source code: gws.plugin.qfieldcloud.delta

Module Contents

gws.plugin.qfieldcloud.delta.cleanup(db: gws.lib.sqlitex.Object, life_time: int)

Remove delta records older than life_time seconds, and the payload links to them.

gws.plugin.qfieldcloud.delta.extract_changes(drs: list[Record]) → list[gws.plugin.qfieldcloud.patcher.Change]

Convert delta records to patcher changes.

gws.plugin.qfieldcloud.delta.get_for_payload(db: gws.lib.sqlitex.Object, payload_id: str, user_name: str) → list[Record]

Load the delta records of a payload sent by a user, empty if not found.

gws.plugin.qfieldcloud.delta.get_history(db: gws.lib.sqlitex.Object, user_name: str, limit: int, offset: int) → list[tuple[Record, str]]

Load delta records of a user, newest first, each with the id of the last payload it was sent with.

gws.plugin.qfieldcloud.delta.get_one(db: gws.lib.sqlitex.Object, uid: str, user_name: str) → Record | None

Load a delta record of a user, None if not found.

Link a payload to its delta records, replacing the links stored for the same payload and user.

gws.plugin.qfieldcloud.delta.new_record(uid: str, d: gws.plugin.qfieldcloud.api.Delta, user_name: str) → Record

Create a pending delta record for a delta.

gws.plugin.qfieldcloud.delta.parse_payload(text: str) → gws.plugin.qfieldcloud.api.DeltasPayload

Parse the content of a delta file, raise gws.BadRequestError if it is invalid.

gws.plugin.qfieldcloud.delta.PENDING_TIMEOUT = 300

Time in seconds after which a pending delta is considered failed.

class gws.plugin.qfieldcloud.delta.Record

Bases: gws.Data

A delta as stored on the server, with its status.

client_id: str

Id of the local export on the device.

content: gws.plugin.qfieldcloud.api.Delta

Delta as sent by QField.

created_at: int

Creation time as a timestamp.

created_by: str

Login name of the user who sent the delta.

id: str

Delta id (the uuid of the delta).

output: str

Error message, if the delta could not be applied.

status: gws.plugin.qfieldcloud.api.DeltaStatusType

Delta status.

uid: str

Record uid, a hash of the user and the delta content.

updated_at: int

Last update time as a timestamp.

gws.plugin.qfieldcloud.delta.set_status_for_all(db: gws.lib.sqlitex.Object, drs: list[Record], status: gws.plugin.qfieldcloud.api.DeltaStatusType, output: str = '')

Set the status and output of delta records, in the objects and in the database.

gws.plugin.qfieldcloud.delta.status(dr: Record, payload_id: str) → gws.plugin.qfieldcloud.core.DeltaStatus

Convert a delta record to the status returned for a payload, reporting a stale pending delta as failed.

gws.plugin.qfieldcloud.delta.STORAGE_DDL = Multiline-String
Show Value
"""
    CREATE TABLE IF NOT EXISTS deltas (
        uid TEXT PRIMARY KEY,
        created_by TEXT NOT NULL,
        id TEXT NOT NULL,
        client_id TEXT,
        created_at INTEGER NOT NULL,
        updated_at INTEGER NOT NULL,
        status TEXT NOT NULL,
        output TEXT,
        content TEXT NOT NULL
    );
    CREATE INDEX IF NOT EXISTS deltas_created_at ON deltas (created_at);
    CREATE INDEX IF NOT EXISTS deltas_created_by_created_at ON deltas (created_by, created_at);
    CREATE TABLE IF NOT EXISTS payloads (
        created_by TEXT NOT NULL,
        payload_id TEXT NOT NULL,
        delta_uid TEXT NOT NULL,
        PRIMARY KEY (created_by, payload_id, delta_uid)
    );
    CREATE INDEX IF NOT EXISTS payloads_delta_uid ON payloads (delta_uid);
"""
gws.plugin.qfieldcloud.delta.store_all(db: gws.lib.sqlitex.Object, drs: list[Record])

Store delta records, replacing the stored ones with the same uid.