Commit ea6abc4
authored
fix(key-backup): count only the sessions actually written (#87)
Review finding on #77, after merge.
The import counted every session it decrypted:
```python
client.olm.store.save_inbound_group_session(session)
imported += 1
```
`save_inbound_group_session` ends in an `on_conflict_ignore()` insert,
so a session already in the store is reported as imported while nothing
is written. The run that produced #77 printed `Imported: 18275` against
18272 new rows — three were already there and counted anyway.
That is the same defect #77 was written to fix, one size smaller: the
original code counted sessions it *discarded*, and the inflated number
is what kept it invisible.
Sessions now go through `client.olm.inbound_group_store.add()` first,
which is what nio does when it imports a key itself:
```python
if self.inbound_group_store.add(session):
self.save_inbound_group_session(session)
```
`add()` returns False for a session already held, and `Olm.load()`
populates that in-memory set from the database at startup — which the
script triggers via `client.load_store()`. So a re-import reports what
it actually did instead of claiming the whole backup again.
Sessions already present are reported on their own line, and a run where
everything was already in the store no longer exits non-zero.
## Not covered by a test
The path needs a live backup and a real megolm session; there is no
fixture for either in this repo. The claim rests on nio's own source
(`on_conflict_ignore` in `store/database.py`, the `add()`-then-save
pattern in `crypto/olm_machine.py`) and on the counter mismatch observed
against a live backup. Worth saying plainly rather than implying the
change is covered.1 file changed
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
| 463 | + | |
463 | 464 | | |
464 | 465 | | |
465 | 466 | | |
| |||
485 | 486 | | |
486 | 487 | | |
487 | 488 | | |
488 | | - | |
489 | 489 | | |
490 | | - | |
491 | | - | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
492 | 505 | | |
493 | 506 | | |
494 | 507 | | |
| |||
498 | 511 | | |
499 | 512 | | |
500 | 513 | | |
| 514 | + | |
| 515 | + | |
501 | 516 | | |
502 | | - | |
| 517 | + | |
503 | 518 | | |
504 | 519 | | |
505 | 520 | | |
| |||
0 commit comments