addCursorCondition adds pagination cursor condition to WHERE clause. The compound cursor uses a row-constructor comparison so PostgreSQL can seek directly into the (server_name, version) B-tree index. The OR-decomposed form `server_name > X OR (server_name = X AND version > Y)` is logically equival
(cursor string, argIndex int)
| 155 | // prod). The row-constructor form `(server_name, version) > (X, Y)` is special- |
| 156 | // cased and stays constant-time regardless of cursor depth. |
| 157 | func addCursorCondition(cursor string, argIndex int) (string, []any, int) { |
| 158 | if cursor == "" { |
| 159 | return "", nil, argIndex |
| 160 | } |
| 161 | |
| 162 | // Parse cursor format: "serverName:version" |
| 163 | parts := strings.SplitN(cursor, ":", 2) |
| 164 | if len(parts) == 2 { |
| 165 | cursorServerName := parts[0] |
| 166 | cursorVersion := parts[1] |
| 167 | condition := fmt.Sprintf("(server_name, version) > ($%d, $%d)", argIndex, argIndex+1) |
| 168 | return condition, []any{cursorServerName, cursorVersion}, argIndex + 2 |
| 169 | } |
| 170 | |
| 171 | // Fallback for malformed cursor - treat as server name only for backwards compatibility |
| 172 | condition := fmt.Sprintf("server_name > $%d", argIndex) |
| 173 | return condition, []any{cursor}, argIndex + 1 |
| 174 | } |
| 175 | |
| 176 | func (db *PostgreSQL) ListServers( |
| 177 | ctx context.Context, |
no outgoing calls
no test coverage detected
searching dependent graphs…