diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index 802a7919..8964e4ea 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -279,6 +279,10 @@ class model(dict): for k in sorted_keys: if int(k) < int(last_viewed): + if prev_k == sorted_keys[0]: + # Return the second last one so we dont recommend the same version compares itself + return sorted_keys[1] + return prev_k prev_k = k diff --git a/changedetectionio/tests/unit/test_watch_model.py b/changedetectionio/tests/unit/test_watch_model.py index d7d26d71..8e01bafe 100644 --- a/changedetectionio/tests/unit/test_watch_model.py +++ b/changedetectionio/tests/unit/test_watch_model.py @@ -23,9 +23,16 @@ class TestDiffBuilder(unittest.TestCase): watch.save_history_text(contents=b"hello world", timestamp=109, snapshot_id=str(uuid_builder.uuid4())) watch.save_history_text(contents=b"hello world", timestamp=112, snapshot_id=str(uuid_builder.uuid4())) watch.save_history_text(contents=b"hello world", timestamp=115, snapshot_id=str(uuid_builder.uuid4())) + watch.save_history_text(contents=b"hello world", timestamp=117, snapshot_id=str(uuid_builder.uuid4())) p = watch.get_next_snapshot_key_to_last_viewed assert p == "112", "Correct last-viewed timestamp was detected" + # When there is only one step of difference from the end of the list, it should return second-last change + watch['last_viewed'] = 116 + p = watch.get_next_snapshot_key_to_last_viewed + assert p == "115", "Correct 'second last' last-viewed timestamp was detected when using the last timestamp" + + if __name__ == '__main__': unittest.main()