@defrex/autobuild-postgres-store 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/store.ts +20 -13
- package/src/tickets.ts +1 -0
package/package.json
CHANGED
package/src/store.ts
CHANGED
|
@@ -77,6 +77,7 @@ import {
|
|
|
77
77
|
DIGEST_EVENT_TYPES,
|
|
78
78
|
type DigestEventRow,
|
|
79
79
|
REPOSITORY_STATE_EVENT_TYPES,
|
|
80
|
+
REPOSITORY_LATEST_EVENT_TYPES,
|
|
80
81
|
readRepoStateEventsWithAnchorRecheck,
|
|
81
82
|
reduceBuildDigest,
|
|
82
83
|
} from '@defrex/autobuild/store-adapter'
|
|
@@ -1091,10 +1092,6 @@ export class PostgresBuildStore implements BuildStore {
|
|
|
1091
1092
|
// select; an append after the final re-probe is an ordinary post-read
|
|
1092
1093
|
// concurrent append, not this race.
|
|
1093
1094
|
const durableList = [...REPOSITORY_STATE_EVENT_TYPES]
|
|
1094
|
-
// `repo` is $1; the anchored select also spends $2 on the anchor, so the
|
|
1095
|
-
// type list's placeholders start at the right offset per branch.
|
|
1096
|
-
const placeholders = (start: number) =>
|
|
1097
|
-
durableList.map((_, index) => `$${index + start}`).join(', ')
|
|
1098
1095
|
return readRepoStateEventsWithAnchorRecheck(
|
|
1099
1096
|
async () => {
|
|
1100
1097
|
// The probe below is an aggregate: MAX() always returns exactly one row —
|
|
@@ -1115,16 +1112,26 @@ export class PostgresBuildStore implements BuildStore {
|
|
|
1115
1112
|
return probe?.no_anchor ? undefined : num(probe?.seq)
|
|
1116
1113
|
},
|
|
1117
1114
|
async (anchor) => {
|
|
1118
|
-
const
|
|
1115
|
+
const bindings: (string | number)[] = [repo]
|
|
1116
|
+
const bind = (value: string | number) => {
|
|
1117
|
+
bindings.push(value)
|
|
1118
|
+
return `$${bindings.length}`
|
|
1119
|
+
}
|
|
1120
|
+
const durable = `type IN (${durableList.map(bind).join(', ')})`
|
|
1121
|
+
const latestTypes = REPOSITORY_LATEST_EVENT_TYPES.map(bind)
|
|
1122
|
+
const latest = latestTypes.map(
|
|
1123
|
+
(type) =>
|
|
1124
|
+
`(type = ${type} AND seq = (SELECT seq FROM repo_events WHERE repo = $1 AND type = ${type} ORDER BY seq DESC LIMIT 1))`,
|
|
1125
|
+
)
|
|
1126
|
+
const tail =
|
|
1119
1127
|
anchor === undefined
|
|
1120
|
-
?
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
),
|
|
1128
|
+
? []
|
|
1129
|
+
: [`(seq >= ${bind(anchor)} AND type NOT IN (${latestTypes.join(', ')}))`]
|
|
1130
|
+
const rows: Row[] = await this.run((q) =>
|
|
1131
|
+
q.unsafe(
|
|
1132
|
+
`SELECT * FROM repo_events WHERE repo = $1 AND (${[durable, ...tail, ...latest].join(' OR ')}) ORDER BY seq`,
|
|
1133
|
+
bindings,
|
|
1134
|
+
),
|
|
1128
1135
|
)
|
|
1129
1136
|
return rows.map((row) => ({
|
|
1130
1137
|
repo: String(row.repo),
|
package/src/tickets.ts
CHANGED
|
@@ -141,6 +141,7 @@ export class PostgresTicketSource implements TicketSource {
|
|
|
141
141
|
title,
|
|
142
142
|
body: String(row.body),
|
|
143
143
|
state: String(row.state),
|
|
144
|
+
resolved: String(row.state) === this.lifecycle.done,
|
|
144
145
|
labels: strings(row.labels),
|
|
145
146
|
...(blockedBy.length > 0 ? { blockedBy } : {}),
|
|
146
147
|
}
|