@defrex/autobuild-postgres-store 0.10.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defrex/autobuild-postgres-store",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "engines": {
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 rows: Row[] = await this.run((q) =>
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
- ? q.unsafe(
1121
- `SELECT * FROM repo_events WHERE repo = $1 AND type IN (${placeholders(2)}) ORDER BY seq`,
1122
- [repo, ...durableList],
1123
- )
1124
- : q.unsafe(
1125
- `SELECT * FROM repo_events WHERE repo = $1 AND (seq >= $2 OR type IN (${placeholders(3)})) ORDER BY seq`,
1126
- [repo, anchor, ...durableList],
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
  }