Open spwoodcock opened 3 months ago
@spwoodcock this would really be a great to improve FMTM from TM cross learning session. Liked your idea of partitioning of task history table
@spwoodcock are we still on for partitioning or we can have further discussion to reach to some strong decision of whether to partition the tables or archiving the very old data would be preferable.
For TM or FMTM?
No to partitioning for both I think.
But we could archive old data for TM 👍 FMTM doesn't have any old data to archive yet!
We could maybe consider an archive ability in the UI, but I think a better option is to have export/import functionality, then archive the exported zip somewhere.
@spwoodcock Do we fill a row for each task in the task_events
table with the default state when we create tasks? Or else how does the query above above that you have in finish work? My guess is we pre-fill a row for each task in the task_event table when creating the tasks.
I don't think we want to do that as it adds unnecessary clutter to table.
If there is no record then we know the state is ready to map.
The logic isn't fully fleshed out above, as you are right the map
function will have different sql to the finish
function.
The map
sql should check if there is no record, or if the latest entry is UNLOCKED_TO_MAP (I.e. it was reset and a record was made)
I was looking into this code by qeef
https://git.sr.ht/~qeef/dd-hot-tm/tree/master/item/hot_tm_proposal/database/actions_history.py
In the create_project function , he has filled actions table with unlocked to map
state for each task at the beginning. So, I was wondering if we would want to follow the same pattern
I think adding that data is redundant personally.
It can probably work by adding an EXISTS clause to the logic or something instead.
But if that doesn't work then adding entries for each task could work for now
@nrjadkry do you think logic like this could work?
WITH last AS (
SELECT *
FROM task_events
WHERE project_id = $1 AND task_id = $2
ORDER BY aid DESC
LIMIT 1
),
released AS (
SELECT COUNT(*) = 0 AS no_record
FROM task_events
WHERE project_id = $1 AND task_id = $2 AND event = 'RELEASED_FOR_MAPPING'
)
INSERT INTO task_events (project_id, task_id, event, comment, user_id)
SELECT $1, $2, 'LOCKED_FOR_MAPPING', 'Note: xxx', $3
FROM last, released
WHERE (last.event = 'RELEASED_FOR_MAPPING' OR released.no_record = true)
RETURNING project_id, task_id, user_id;
@spwoodcock This actually works. Just had to make a small change in the query here at the last joining last and released.
FROM last
RIGHT JOIN released ON true
WHERE (last.state = :unlocked_to_map_state OR released.no_record = true);
Problem
qeef
a community volunteer:The key unit of change in tasking managers is the task status / events.
Currently we have:
tasks
andtasks_history
.DB Redesign
Related to other issues in this milestone: https://github.com/hotosm/fmtm/milestone/39
task_events table
Better indexing
Refactor enums
Events via the API:
and the available states of an object in the db:
task_events.state
should use the State enum + we could probably also reuse this for the Entitiesstatus
field.Updating state via the API
Models
tasks.task_status: TaskStatus
withtasks.state: State
.TaskHistory
model toTaskState
:Task
model that is nested as a list of tasks under theProject
model could be refactored too.locked_by
etc fields, removetask_status
.history_recent
, which includes the most recent 10 TaskState objects.Endpoints
Endpoint to update task state via events:
Database logic
ASSIGN
event the task state should move tolocked for mapping
, with the user_id set to the requested user id. The user should also be notified as part of the logic.In this flow, the task_events are a centralised data store where each event is stored as a sequence of immutable records, also called a log. Each new event is appended to the end of the list. This is the single source of truth for the task state, which can be accessed from multiple places.