Skip to content

Commit c25b5cb

Browse files
committed
fix: optimize a little bit
1 parent 170cd9d commit c25b5cb

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

lib/services/shopinbit/shopinbit_service.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ class ShopInBitService {
164164
) async {
165165
final int id = ref.id;
166166
try {
167+
final ShopInBitTicket? existing = await db.shopInBitTicketsDao.getByApiId(
168+
id,
169+
);
170+
171+
// Terminal-state short-circuit: nothing about a closed/merged ticket
172+
// will change server-side, so skip the three API calls entirely.
173+
if (existing != null &&
174+
TicketState.fromString(existing.statusRaw).isTerminal) {
175+
completer.complete();
176+
return;
177+
}
178+
167179
// Ensure the client points at the right key for this ticket's calls.
168180
client.externalCustomerKey = customerKey;
169181

@@ -176,10 +188,6 @@ class ShopInBitService {
176188
client.getMessages(id),
177189
).wait;
178190

179-
final ShopInBitTicket? existing = await db.shopInBitTicketsDao.getByApiId(
180-
id,
181-
);
182-
183191
if (existing == null) {
184192
await _insertHydrated(
185193
ref: ref,

lib/services/shopinbit/src/models/ticket.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ enum TicketState {
3333
);
3434
return TicketState.unknown;
3535
}
36+
37+
bool get isTerminal => switch(this) {
38+
.closed || .closedCancelled || .merged => true,
39+
_ => false,
40+
} ;
3641
}
3742

3843
class TicketRef {

0 commit comments

Comments
 (0)