14.2.102. camcops_server.cc_modules.cc_taskcollection


Copyright (C) 2012-2019 Rudolf Cardinal (rudolf@pobox.com).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <http://www.gnu.org/licenses/>.

Classes to fetch tasks from the database as efficiently as possible.

class camcops_server.cc_modules.cc_taskcollection.FetchThread(req: CamcopsRequest, task_class: Type[camcops_server.cc_modules.cc_task.Task], factory: TaskCollection, **kwargs)[source]

Thread to fetch tasks in parallel.


run() → None[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class camcops_server.cc_modules.cc_taskcollection.TaskCollection(req: CamcopsRequest, taskfilter: camcops_server.cc_modules.cc_taskfilter.TaskFilter = None, as_dump: bool = False, sort_method_by_class: camcops_server.cc_modules.cc_taskcollection.TaskSortMethod = <TaskSortMethod.NONE: 0>, sort_method_global: camcops_server.cc_modules.cc_taskcollection.TaskSortMethod = <TaskSortMethod.NONE: 0>, current_only: bool = True, via_index: bool = True, export_recipient: ExportRecipient = None)[source]

Represent a potential or instantiated call to fetch tasks from the database.

The caller may want them in a giant list (e.g. task viewer, CTVs), or split by task class (e.g. trackers).


Returns a list of all appropriate task instances.


Returns a list of all appropriate task instances, or index entries, or a query returning them.

  • Returning a list of tasks is fine, but the results of this function may be paginated (e.g. in the main task view), so the end result may be that e.g. 20,000 tasks are fetched and 20 are shown.
  • More efficient is to fetch 20,000 indexes from the single index table, and fetch only the 20 tasks we need.
  • More efficient still is to fetch the 20 indexes we need, and then their task.

Returns the request’s database session.

gen_all_tasks_or_indexes() → Generator[[Union[camcops_server.cc_modules.cc_task.Task, camcops_server.cc_modules.cc_taskindex.TaskIndexEntry], NoneType], NoneType][source]

Generates tasks or index entries.

gen_tasks_by_class() → Generator[[camcops_server.cc_modules.cc_task.Task, NoneType], NoneType][source]

Generates all tasks, class-wise.

gen_tasks_in_global_order() → Generator[[camcops_server.cc_modules.cc_task.Task, NoneType], NoneType][source]

Generates all tasks, in the global order.

task_classes() → List[Type[camcops_server.cc_modules.cc_task.Task]][source]

Return a list of task classes that we want.

tasks_for_task_class(task_class: Type[camcops_server.cc_modules.cc_task.Task]) → List[camcops_server.cc_modules.cc_task.Task][source]

Returns all appropriate task instances for a specific task type.

class camcops_server.cc_modules.cc_taskcollection.TaskSortMethod[source]

Enum representing ways to sort tasks.

camcops_server.cc_modules.cc_taskcollection.sort_tasks_in_place(tasklist: List[camcops_server.cc_modules.cc_task.Task], sortmethod: camcops_server.cc_modules.cc_taskcollection.TaskSortMethod) → None[source]

Sort a list of tasks, in place, according to sortmethod.

camcops_server.cc_modules.cc_taskcollection.task_when_created_sorter(task: camcops_server.cc_modules.cc_task.Task) → Union[typing.Tuple[pendulum.datetime.DateTime, datetime.datetime], cardinal_pythonlib.sort.MinType][source]

Function to sort tasks by their creation date/time (with upload date/time as a tiebreak for consistent ordering).