Skip to content

Commit 48e5ec2

Browse files
committed
fix(db): keep event-rule and tag-slot reads on the primary
1 parent 328963e commit 48e5ec2

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

apps/sim/lib/knowledge/tags/service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export async function getNextAvailableSlot(
9999
export async function getDocumentTagDefinitions(
100100
knowledgeBaseId: string
101101
): Promise<DocumentTagDefinition[]> {
102-
const definitions = await dbReplica
102+
const definitions = await db
103103
.select({
104104
id: knowledgeBaseTagDefinitions.id,
105105
knowledgeBaseId: knowledgeBaseTagDefinitions.knowledgeBaseId,
@@ -123,7 +123,7 @@ export async function getDocumentTagDefinitions(
123123
* Get all tag definitions for a knowledge base (alias for compatibility)
124124
*/
125125
export async function getTagDefinitions(knowledgeBaseId: string): Promise<TagDefinition[]> {
126-
const tagDefinitions = await dbReplica
126+
const tagDefinitions = await db
127127
.select({
128128
id: knowledgeBaseTagDefinitions.id,
129129
tagSlot: knowledgeBaseTagDefinitions.tagSlot,

apps/sim/lib/workspace-events/rules.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dbReplica } from '@sim/db'
1+
import { db } from '@sim/db'
22
import { workflowExecutionLogs } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
44
import { and, avg, count, desc, eq, gte, ne, type SQL, sql } from 'drizzle-orm'
@@ -22,7 +22,7 @@ export function excludeSimExecutionsCondition(): SQL {
2222
}
2323

2424
async function checkConsecutiveFailures(workflowId: string, threshold: number): Promise<boolean> {
25-
const recentLogs = await dbReplica
25+
const recentLogs = await db
2626
.select({ level: workflowExecutionLogs.level })
2727
.from(workflowExecutionLogs)
2828
.where(and(eq(workflowExecutionLogs.workflowId, workflowId), excludeSimExecutionsCondition()))
@@ -51,7 +51,7 @@ async function checkFailureRate(
5151

5252
// Single DB-side aggregate: the window is user-configured and this runs on
5353
// the execution-completion path, so never materialize the in-window rows.
54-
const result = await dbReplica
54+
const result = await db
5555
.select({
5656
total: count(),
5757
errors: count(sql`case when ${workflowExecutionLogs.level} = 'error' then 1 end`),
@@ -82,7 +82,7 @@ async function checkLatencySpike(
8282
): Promise<boolean> {
8383
const windowStart = new Date(Date.now() - windowHours * 60 * 60 * 1000)
8484

85-
const result = await dbReplica
85+
const result = await db
8686
.select({
8787
avgDuration: avg(workflowExecutionLogs.totalDurationMs),
8888
count: count(),
@@ -114,7 +114,7 @@ async function checkErrorCount(
114114
): Promise<boolean> {
115115
const windowStart = new Date(Date.now() - windowHours * 60 * 60 * 1000)
116116

117-
const result = await dbReplica
117+
const result = await db
118118
.select({ count: count() })
119119
.from(workflowExecutionLogs)
120120
.where(

0 commit comments

Comments
 (0)