Skip to content
Snippets Groups Projects
Commit a07f4204 authored by Valentin Rigal's avatar Valentin Rigal
Browse files

Drop Ponos non Postgres DB support

parent fca6175b
No related branches found
No related tags found
1 merge request!1908Drop Ponos non Postgres DB support
from django.db import connections
from django.db.models import Manager
......@@ -6,31 +5,20 @@ class TaskManager(Manager):
def parents(self, task):
"""
List all tasks that a task depends on, directly or not.
When using a PostgreSQL database, this will use a recursive query.
This falls back to a recursive generator on other databases.
A PostgreSQL recursive query is used for better performances.
"""
if connections[self.db].vendor == "postgresql":
return self.raw(
"""
with recursive parents(id) as (
select to_task_id
from ponos_task_parents j
where j.from_task_id = %s
union all
select j.to_task_id
from ponos_task_parents as j, parents
where j.from_task_id = parents.id
)
select distinct * from parents
""",
[task.id],
return self.raw(
"""
with recursive parents(id) as (
select to_task_id
from ponos_task_parents j
where j.from_task_id = %s
union all
select j.to_task_id
from ponos_task_parents as j, parents
where j.from_task_id = parents.id
)
else:
def _parents_python(task):
yield from task.parents.all()
for parent in task.parents.all():
yield from _parents_python(parent)
return _parents_python(task)
select distinct * from parents
""",
[task.id],
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment