Resolver
BlockCutVertex = tuple[Literal['b'], int] | tuple[Literal['c'], PathVertex]
module-attribute
A vertex in conflict_paths()'s block-cut tree: ("b", i) for the ith biconnected block, ("c", v) for cut vertex v.
PathVertex = tuple[Literal['n'], Vertex] | tuple[Literal['r'], int]
module-attribute
A vertex in resolve()'s graph of candidates: ("n", node) for a resolver root or new vertex, ("r", k) for the kth candidate.
Record = dict[str, Any]
module-attribute
One source row: {"source": str, "ids": {provider ID field: ID}, "meta": {...}}.
ids holds the IDs this row syncs together; source and meta are carried along untouched. IDs are normalized when read (see string_stringify_object_id()), so numeric IDs end up as strings and missing or blank IDs are ignored.
Vertex = tuple[str, Hashable]
module-attribute
A (provider ID field, ID) pair, where the field is named {provider}_{object_type}_id, e.g. ("provider_a_object_id", "12345").
ObjectResolver
Applies a graph-based approach to resolving object identifiers from multiple runs of SyncEngine.synchronize() to properly identify related identifiers and discard conflicts.
Within the graph, every (provider, ID) pair is a vertex, and a sync between two IDs is an edge. ObjectResolver builds graph "components" out of these vertices to represent objects. By design, these components may hold AT MOST one ID per provider.
More methodology details are available in ObjectResolver.resolve().
Source code in src/glass_onion/resolver.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
added = to_frame([])
instance-attribute
The records the latest resolve() call added to the resolver, flattened by to_frame().
anchored = {}
instance-attribute
The vertex sets in kept, each under the one of its vertices held by the fewest kept records when it was added. Used to find records inside a new record without scanning every record that shares a common vertex.
covers = {}
instance-attribute
For each vertex, the vertex sets of the records in kept that hold it, used to find records a new record is inside.
ids = {}
instance-attribute
Each component's IDs as {provider ID field: ID}, keyed by the component's root.
kept = {}
instance-attribute
Every record in records, keyed by its vertex set.
parent = {}
instance-attribute
Each vertex's parent in the union-find. A component's root is its own parent.
records = {}
instance-attribute
The records that built each component, keyed by the component's root. A record whose IDs are all in another kept record is not kept.
rejected = to_frame([], [])
instance-attribute
The records the latest resolve() call rejected, flattened by to_frame(). Each row's conflicts holds the records it conflicted with: every resolver record involved in the conflict, followed by any other records rejected in the same conflict.
__init__()
Creates a new, empty ObjectResolver.
Source code in src/glass_onion/resolver.py
add_record(record)
Adds a record's vertices to the resolver and merges them into a single component.
Only the largest of a set of nested records is kept, whatever order they arrive in: a record whose vertices are all in one kept record (an exact repeat, or a 2-ID record inside a 3-ID record) is skipped, and kept records whose vertices are all in the new record are removed. A smaller record adds no IDs or links the larger one doesn't, and keeping it would grow records with every repeated sync. Of two exact repeats, the earlier is kept. A record linking IDs from several kept records is not a repeat, even if they're all in one component. Smaller components are merged into the largest one, so each merge copies only the smaller side's IDs and records.
Callers must check for provider conflicts first: this method will happily merge two IDs from the same provider. resolve() does this check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
Record
|
the record to add. It must have at least one valid ID. |
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/glass_onion/resolver.py
components()
Lists the resolver's connected components (IE: its objects).
Returns:
| Type | Description |
|---|---|
list[tuple[dict[str, Hashable], list[Record]]]
|
One |
Source code in src/glass_onion/resolver.py
conflict_paths(adj, terminals)
Finds every vertex of an undirected graph that lies on a simple path between two distinct terminal vertices.
Methodology
- Split the terminal vertices' connected component into biconnected blocks using an iterative version of Tarjan's algorithm.
- Build the block-cut tree of those blocks and their cut vertices.
- Prune leaves of the tree that hold no terminal vertex, until only the paths between terminal vertices remain. Every vertex of a remaining block lies on a simple path between two terminal vertices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adj
|
dict[PathVertex, set[PathVertex]]
|
the graph's adjacency sets. The graph must have no parallel edges. |
required |
terminals
|
set[PathVertex]
|
two or more terminal vertices of |
required |
Returns:
| Type | Description |
|---|---|
set[PathVertex]
|
The set of PathVertex objects lying on a simple path between two of |
Source code in src/glass_onion/resolver.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
find(v)
Finds the root vertex of a vertex's component, compressing the path along the way.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
Vertex
|
a vertex already in the resolver. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
if |
Returns:
| Type | Description |
|---|---|
Vertex
|
The root Vertex of |
Source code in src/glass_onion/resolver.py
resolve(records)
Merges multi-ID records into the resolver, each as a single unit, and sets added and rejected to this call's results.
A record is rejected if merging it would put two IDs from one provider into the same component. The result doesn't depend on the order of records.
Methodology
- Drop records with no valid IDs (see string_stringify_object_id()). These appear in neither
addednorrejected. - Reject each record that conflicts with the resolver as it stands.
- Of the remaining records, reject those on a path linking two IDs from one provider (see conflict_paths()). Records that merely touch the same object are kept, and records that only conflict with each other are all rejected.
- Add the remaining records to the resolver, largest first. Records whose IDs are all in one record from the resolver or this batch are skipped and appear in neither
addednorrejected; resolver records whose IDs are all in an added record are removed from the resolver (see add_record()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[Record]
|
the records to merge. |
required |
Source code in src/glass_onion/resolver.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
to_frame(records, conflicts=None)
Flattens records into a DataFrame shaped like SyncEngine.synchronize() output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
list[Record]
|
the records to flatten. |
required |
conflicts
|
list[list[Record]] | None
|
if given, the records each of |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame with one row per record: a |
Source code in src/glass_onion/resolver.py
vertices(record)
Builds the (provider ID field, ID) vertices for a record. IDs are normalized and invalid IDs dropped (see string_stringify_object_id()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
Record
|
the record to build vertices for. |
required |
Returns:
| Type | Description |
|---|---|
list[Vertex]
|
A list of Vertex objects, one per valid ID in |