Skip to content

Commit

Permalink
chore: updated queryset for soft delete
Browse files Browse the repository at this point in the history
  • Loading branch information
NarayanBavisetti committed Oct 16, 2024
1 parent cc613e5 commit 75a2783
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions apiserver/plane/api/serializers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def update(self, instance, validated_data):
updated_by_id = instance.updated_by_id

if assignees is not None:
IssueAssignee.objects.filter(issue=instance).delete()
IssueAssignee.objects.filter(issue=instance).delete(soft=False)
IssueAssignee.objects.bulk_create(
[
IssueAssignee(
Expand All @@ -229,7 +229,7 @@ def update(self, instance, validated_data):
)

if labels is not None:
IssueLabel.objects.filter(issue=instance).delete()
IssueLabel.objects.filter(issue=instance).delete(soft=False)
IssueLabel.objects.bulk_create(
[
IssueLabel(
Expand Down
8 changes: 6 additions & 2 deletions apiserver/plane/app/serializers/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ def update(self, instance, validated_data):
updated_by_id = instance.updated_by_id

if assignees is not None:
DraftIssueAssignee.objects.filter(draft_issue=instance).delete()
DraftIssueAssignee.objects.filter(draft_issue=instance).delete(
soft=False
)
DraftIssueAssignee.objects.bulk_create(
[
DraftIssueAssignee(
Expand All @@ -186,7 +188,9 @@ def update(self, instance, validated_data):
)

if labels is not None:
DraftIssueLabel.objects.filter(draft_issue=instance).delete()
DraftIssueLabel.objects.filter(draft_issue=instance).delete(
soft=False
)
DraftIssueLabel.objects.bulk_create(
[
DraftIssueLabel(
Expand Down
4 changes: 2 additions & 2 deletions apiserver/plane/app/serializers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def update(self, instance, validated_data):
updated_by_id = instance.updated_by_id

if assignees is not None:
IssueAssignee.objects.filter(issue=instance).delete()
IssueAssignee.objects.filter(issue=instance).delete(soft=False)
IssueAssignee.objects.bulk_create(
[
IssueAssignee(
Expand All @@ -218,7 +218,7 @@ def update(self, instance, validated_data):
)

if labels is not None:
IssueLabel.objects.filter(issue=instance).delete()
IssueLabel.objects.filter(issue=instance).delete(soft=False)
IssueLabel.objects.bulk_create(
[
IssueLabel(
Expand Down
12 changes: 11 additions & 1 deletion apiserver/plane/db/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ class Meta:
abstract = True


class SoftDeletionQuerySet(models.QuerySet):
def delete(self, soft=True):
if soft:
return self.update(deleted_at=timezone.now())
else:
return super().delete()


class SoftDeletionManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(deleted_at__isnull=True)
return SoftDeletionQuerySet(self.model, using=self._db).filter(
deleted_at__isnull=True
)


class SoftDeleteModel(models.Model):
Expand Down
5 changes: 2 additions & 3 deletions apiserver/plane/db/models/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Module imports
from plane.utils.html_processor import strip_tags
from plane.db.mixins import SoftDeletionManager

from .project import ProjectBaseModel

Expand Down Expand Up @@ -79,7 +80,7 @@ def get_default_display_properties():


# TODO: Handle identifiers for Bulk Inserts - nk
class IssueManager(models.Manager):
class IssueManager(SoftDeletionManager):
def get_queryset(self):
return (
super()
Expand All @@ -90,7 +91,6 @@ def get_queryset(self):
| models.Q(issue_inbox__status=2)
| models.Q(issue_inbox__isnull=True)
)
.filter(deleted_at__isnull=True)
.filter(state__is_triage=False)
.exclude(archived_at__isnull=False)
.exclude(project__archived_at__isnull=False)
Expand Down Expand Up @@ -172,7 +172,6 @@ class Issue(ProjectBaseModel):
blank=True,
)

objects = models.Manager()
issue_objects = IssueManager()

class Meta:
Expand Down
4 changes: 2 additions & 2 deletions apiserver/plane/space/serializer/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def update(self, instance, validated_data):
updated_by_id = instance.updated_by_id

if assignees is not None:
IssueAssignee.objects.filter(issue=instance).delete()
IssueAssignee.objects.filter(issue=instance).delete(soft=False)
IssueAssignee.objects.bulk_create(
[
IssueAssignee(
Expand All @@ -438,7 +438,7 @@ def update(self, instance, validated_data):
)

if labels is not None:
IssueLabel.objects.filter(issue=instance).delete()
IssueLabel.objects.filter(issue=instance).delete(soft=False)
IssueLabel.objects.bulk_create(
[
IssueLabel(
Expand Down

0 comments on commit 75a2783

Please sign in to comment.