forked from rapidpro/rapidpro
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5607 from nyaruka/ticket_counts_v2_pt5
Stop writing old ticket counts
- Loading branch information
Showing
7 changed files
with
48 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 5.1.2 on 2024-10-31 21:11 | ||
|
||
from django.db import migrations | ||
|
||
SQL = """ | ||
---------------------------------------------------------------------- | ||
-- Trigger procedure to update contact ticket counts | ||
---------------------------------------------------------------------- | ||
CREATE OR REPLACE FUNCTION temba_ticket_on_change() RETURNS TRIGGER AS $$ | ||
BEGIN | ||
IF TG_OP = 'INSERT' THEN -- new ticket inserted | ||
IF NEW.status = 'O' THEN | ||
UPDATE contacts_contact SET ticket_count = ticket_count + 1, modified_on = NOW() WHERE id = NEW.contact_id; | ||
END IF; | ||
ELSIF TG_OP = 'UPDATE' THEN -- existing ticket updated | ||
IF OLD.status = 'O' AND NEW.status = 'C' THEN -- ticket closed | ||
UPDATE contacts_contact SET ticket_count = ticket_count - 1, modified_on = NOW() WHERE id = OLD.contact_id; | ||
ELSIF OLD.status = 'C' AND NEW.status = 'O' THEN -- ticket reopened | ||
UPDATE contacts_contact SET ticket_count = ticket_count + 1, modified_on = NOW() WHERE id = OLD.contact_id; | ||
END IF; | ||
ELSIF TG_OP = 'DELETE' THEN -- existing ticket deleted | ||
IF OLD.status = 'O' THEN -- open ticket deleted | ||
UPDATE contacts_contact SET ticket_count = ticket_count - 1, modified_on = NOW() WHERE id = OLD.contact_id; | ||
END IF; | ||
END IF; | ||
RETURN NULL; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
DROP FUNCTION temba_insert_ticketcount_for_assignee(INTEGER, INTEGER, CHAR(1), INT); | ||
DROP FUNCTION temba_insert_ticketcount_for_topic(INTEGER, INTEGER, CHAR(1), INT); | ||
""" | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("tickets", "0071_backfill_item_counts")] | ||
|
||
operations = [migrations.RunSQL(SQL)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
from temba.utils.crons import cron_task | ||
|
||
from .models import TicketCount, TicketDailyCount, TicketDailyTiming | ||
from .models import TicketDailyCount, TicketDailyTiming | ||
|
||
|
||
@cron_task(lock_timeout=7200) | ||
def squash_ticket_counts(): | ||
TicketCount.squash() | ||
TicketDailyCount.squash() | ||
TicketDailyTiming.squash() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters