Skip to content

Commit 21e2399

Browse files
committed
Remove override values
1 parent 2c98363 commit 21e2399

File tree

2 files changed

+64
-47
lines changed

2 files changed

+64
-47
lines changed

backend/src/db/schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ export const queuePriorityConfigs = sqliteTable('queue_priority_configs', {
108108
id: integer('id').primaryKey({ autoIncrement: true }),
109109
queueType: text('queue_type').notNull().unique(), // 'ump' or 'dmp'
110110
priorityType: text('priority_type').notNull(), // 'Config', 'OverrideConfig', or 'Disabled'
111-
overrideValues: text('override_values'), // JSON stringified [threshold, drop_threshold] for OverrideConfig, null otherwise
112111
lastUpdated: integer('last_updated', { mode: 'timestamp' })
113112
.notNull()
114113
.$defaultFn(() => new Date()),

backend/src/services/BlockProcessor.ts

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,42 +1031,51 @@ export class BlockProcessor {
10311031
): Promise<void> {
10321032
try {
10331033
const priorityType = queuePriority.type;
1034-
const overrideValues = priorityType === 'OverrideConfig'
1035-
? JSON.stringify(queuePriority.value)
1036-
: null;
10371034

1038-
// Upsert to database
10391035
const existing = await db.query.queuePriorityConfigs.findFirst({
10401036
where: eq(queuePriorityConfigs.queueType, 'ump'),
10411037
});
10421038

1043-
if (existing) {
1039+
// Only update if this is the first time, or if the priority type has actually changed
1040+
if (!existing) {
1041+
// First time - insert new record
1042+
await db.insert(queuePriorityConfigs).values({
1043+
queueType: 'ump',
1044+
priorityType,
1045+
lastUpdated: new Date(item.timestamp!),
1046+
});
1047+
1048+
eventService.emit('umpQueuePriority', {
1049+
type: priorityType,
1050+
timestamp: new Date(item.timestamp!).toISOString(),
1051+
});
1052+
1053+
Log.service({
1054+
service: 'UMP Queue Priority',
1055+
action: 'UMP queue priority config initialized',
1056+
details: { type: priorityType },
1057+
});
1058+
} else if (existing.priorityType !== priorityType) {
1059+
// Priority type has changed - update existing record
10441060
await db.update(queuePriorityConfigs)
10451061
.set({
10461062
priorityType,
1047-
overrideValues,
10481063
lastUpdated: new Date(item.timestamp!),
10491064
})
10501065
.where(eq(queuePriorityConfigs.queueType, 'ump'));
1051-
} else {
1052-
await db.insert(queuePriorityConfigs).values({
1053-
queueType: 'ump',
1054-
priorityType,
1055-
overrideValues,
1056-
lastUpdated: new Date(item.timestamp!),
1057-
});
1058-
}
10591066

1060-
eventService.emit('umpQueuePriority', {
1061-
type: priorityType,
1062-
timestamp: new Date(item.timestamp!).toISOString(),
1063-
});
1067+
eventService.emit('umpQueuePriority', {
1068+
type: priorityType,
1069+
timestamp: new Date(item.timestamp!).toISOString(),
1070+
});
10641071

1065-
Log.service({
1066-
service: 'UMP Queue Priority',
1067-
action: 'UMP queue priority config retrieved',
1068-
details: { type: priorityType },
1069-
});
1072+
Log.service({
1073+
service: 'UMP Queue Priority',
1074+
action: 'UMP queue priority config changed',
1075+
details: { type: priorityType },
1076+
});
1077+
}
1078+
// else: priority type hasn't changed, do nothing
10701079
} catch (error) {
10711080
Log.service({
10721081
service: 'UMP Queue Priority',
@@ -1082,42 +1091,51 @@ export class BlockProcessor {
10821091
): Promise<void> {
10831092
try {
10841093
const priorityType = queuePriority.type;
1085-
const overrideValues = priorityType === 'OverrideConfig'
1086-
? JSON.stringify(queuePriority.value)
1087-
: null;
10881094

1089-
// Upsert to database
10901095
const existing = await db.query.queuePriorityConfigs.findFirst({
10911096
where: eq(queuePriorityConfigs.queueType, 'dmp'),
10921097
});
10931098

1094-
if (existing) {
1099+
// Only update if this is the first time, or if the priority type has actually changed
1100+
if (!existing) {
1101+
// First time - insert new record
1102+
await db.insert(queuePriorityConfigs).values({
1103+
queueType: 'dmp',
1104+
priorityType,
1105+
lastUpdated: new Date(item.timestamp!),
1106+
});
1107+
1108+
eventService.emit('dmpQueuePriority', {
1109+
type: priorityType,
1110+
timestamp: new Date(item.timestamp!).toISOString(),
1111+
});
1112+
1113+
Log.service({
1114+
service: 'DMP Queue Priority',
1115+
action: 'DMP queue priority config initialized',
1116+
details: { type: priorityType },
1117+
});
1118+
} else if (existing.priorityType !== priorityType) {
1119+
// Priority type has changed - update existing record
10951120
await db.update(queuePriorityConfigs)
10961121
.set({
10971122
priorityType,
1098-
overrideValues,
10991123
lastUpdated: new Date(item.timestamp!),
11001124
})
11011125
.where(eq(queuePriorityConfigs.queueType, 'dmp'));
1102-
} else {
1103-
await db.insert(queuePriorityConfigs).values({
1104-
queueType: 'dmp',
1105-
priorityType,
1106-
overrideValues,
1107-
lastUpdated: new Date(item.timestamp!),
1108-
});
1109-
}
11101126

1111-
eventService.emit('dmpQueuePriority', {
1112-
type: priorityType,
1113-
timestamp: new Date(item.timestamp!).toISOString(),
1114-
});
1127+
eventService.emit('dmpQueuePriority', {
1128+
type: priorityType,
1129+
timestamp: new Date(item.timestamp!).toISOString(),
1130+
});
11151131

1116-
Log.service({
1117-
service: 'DMP Queue Priority',
1118-
action: 'DMP queue priority config retrieved',
1119-
details: { type: priorityType },
1120-
});
1132+
Log.service({
1133+
service: 'DMP Queue Priority',
1134+
action: 'DMP queue priority config changed',
1135+
details: { type: priorityType },
1136+
});
1137+
}
1138+
// else: priority type hasn't changed, do nothing
11211139
} catch (error) {
11221140
Log.service({
11231141
service: 'DMP Queue Priority',

0 commit comments

Comments
 (0)