Blog

Why changing 40 tickets at once broke, and how we fixed it

A bulk status change sent one request per ticket and ran into our rate limit. How we made it one request and one database call, with every rule still checked.

Forty tickets selected, with the bulk action bar and the Change Status panel for 40 tickets

One of our project managers selected about 40 tickets in a sprint list and changed their status with the bulk bar. The screen filled with error messages and the list stopped working. It happened in our staging environment, where we test releases before they go out, but every workspace ran the same code.

This is what the click actually did, and how we turned it into one request and one database call without dropping any of the rules a status change has to follow.

One click, forty requests

The bulk bar looked like one action. Underneath, the browser sent a separate request for every selected ticket, three at a time. The same was true for changing the assignee or the fix version and for moving tickets to another sprint.

Each change also sent out a live update, and each live update made the page reload project data. So 40 tickets meant 40 changes plus a reload for every one of them. All of that counted against the limit on how many requests one person may send per minute. Past the limit, the server answers "Too many requests" (HTTP status 429), and the app showed an error message for every one of those answers.

None of these pieces was new. Recent work had made large selections easy to make, and large selections exposed the loop.

To see it on demand, we lowered the limit and changed 30 tickets. 30 requests went out, 26 came back with "Too many requests", and 26 error messages stacked up on the screen.

Fix one: one request for the whole selection

Each action in the bulk bar now sends one request for the whole selection, even when only one ticket is selected, so there is a single way it works. The answer says how many tickets changed, which ones didn't, and why for each one. A request carries up to 200 tickets. Larger selections go out in batches of 200 and the answers are combined, so you still see one result.

Two smaller changes went with it. When the same error message comes up several times within three seconds, it now shows once. And the page now waits 300 milliseconds after a live update and reloads once, so a bulk change costs about two reloads instead of one per ticket.

Fix two: one database call

The server had the same loop. It ran the single-ticket code once for every selected ticket, and before writing anything it had to check whether each change was allowed. Those checks alone cost several database queries per ticket.

A status change carries real rules. A ticket in a released fix version can't change status. The new status has to exist in the project's workflow. A ticket with open subtasks can't be closed, a rule from A definition-of-done checklist you can copy. A bug report can't be resolved while a ticket that blocks it is still open. Moving tickets to another sprint has rules of its own: a ticket can't move into another project's sprint, a bug report can't leave the CLIENT REPORTS list, and every move shows up in the ticket's Activity.

We put those rules into a single function that runs inside the database itself (PostgreSQL, the database Tiqzen uses). It takes the whole selection, checks every rule for all the tickets together and saves the allowed changes in one go. For each ticket it reports whether it changed and, if not, the same reason the single-ticket path would have given.

That matters to the person clicking. The tickets that can change, change. For the rest, the bulk bar says how many failed, and in some cases why, for example that some tickets still have open subtasks to resolve or cancel before the parent can be closed.

Permission checks went in as well. Your permission rules are handed to the function, which checks each ticket against them. A ticket you aren't allowed to change is reported as denied, and the rest of the selection still goes through. The function may change only a fixed list of fields, checked both in our application and in the function itself, so no request can reach anything else, such as which workspace a ticket belongs to.

Everything around the change stayed in the application: the activity log, live updates and emails. The activity log is now written once for the whole selection, and each project's workflow is read once instead of once per ticket.

Measured on the same 30 tickets, a status change went from 1,740 database statements to 78. The checks and the changes are now that one function call, and the other statements belong to the work around it.

The price we pay

The rules now exist twice: once in our application code, for changes to a single ticket, and once in the database, for bulk changes. Two copies of a rule can drift apart without anyone noticing, and the automatic checks that run on every code change work without a database, so they can't catch it.

The guard is a set of tests that we run by hand against a throwaway database. Each status scenario goes through both paths on the same test data, and the tests check that both reach the same outcome and leave the ticket in the same state, down to its status, its timestamps and the resolution text. Other tests cover the selection as a whole: an unknown ticket doesn't stop the rest, results come back in the order of the selection, any size costs one call, and another workspace's tickets are never touched.

The tests paid off on their first run, when they found the one case where the two paths disagreed. When the requested status wasn't part of the workflow, the old bulk path reported an unknown error, while the new function named the real problem, an invalid status. We kept the clearer answer and gave that case its own test, so the difference stays visible.

Still to do

Two drag-and-drop actions still send one request per ticket: dragging several selected tickets onto another status group in the sprint list, and dropping a selection onto a sprint in the sidebar. With the change to error messages they no longer flood the screen, and they are next in line.

The lesson we took is about where to look. A loop in the browser often has a twin on the server, and counting requests only finds the first one. Counting database statements per action found the second, and we now check that number whenever an action touches more than one ticket.

← All posts

Start tracking bugs the modern way

Free plan includes the capture widget (100 reports a month) and MCP access. No credit card, live in minutes.