mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 12:26:19 -05:00
Config versions: keep unsaved rows after a no-delete import, count every owned write
Review fixes: - An import without deletes (no database version yet) no longer records the file's version, which let the next startup delete the rows it had kept. The version stays unknown, and the database is saved into the file instead; a successful save records the version. A save after a partial import is refused, so the version stays unknown until an import applies the whole file. - An import removes the database's version while it runs, so its own writes do not count: one that fails partway no longer looks newer than the file and gets saved over it on the next startup. - Playlists imported without deletes keep their database items in order; the file's other items are added after their neighbor from the file. - A Download leaving a Channel or Repo counts for that Collection's config (collection_id loads its previous value). - Bulk writes count: untagging, retrying Downloads, deleting a duplicate's Download, removing many items from a playlist. Deleting Downloads by id counts channels.yaml/repos.yaml only for their Downloads. - Only a playlist's items count for playlists.yaml (author and subject Collections have items too). Collection kinds are looked up once per flush. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2132b2826b
commit
5cf6309aa4
14 changed files with 310 additions and 56 deletions
|
|
@ -3,6 +3,7 @@ import pytest
|
|||
from modules.repos import lib
|
||||
from modules.repos.models import Repository
|
||||
from wrolpi.collections.models import Collection
|
||||
from wrolpi.conftest import config_versions_lost
|
||||
from wrolpi.downloader import Download, DownloadFrequency
|
||||
|
||||
|
||||
|
|
@ -31,9 +32,12 @@ async def test_dump_and_import(test_session, test_directory, async_client, test_
|
|||
for repo in test_session.query(Repository).all():
|
||||
lib._delete_repository(test_session, repo)
|
||||
test_session.commit()
|
||||
config_versions_lost(test_session)
|
||||
assert test_session.query(Collection).count() == 0
|
||||
|
||||
config.import_config()
|
||||
# Imported without deletes; the database is saved, which records its version.
|
||||
await await_switches()
|
||||
test_session.expire_all()
|
||||
repos = {i.name: i for i in test_session.query(Repository)}
|
||||
assert repos['kiwix-tools'].directory == test_directory / 'repos/software/kiwix-tools'
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import yaml
|
|||
|
||||
from modules.repos import lib
|
||||
from modules.repos.models import Repository
|
||||
from wrolpi.conftest import config_versions_lost
|
||||
from wrolpi.downloader import Download, DownloadFrequency, DownloadStatus
|
||||
|
||||
|
||||
|
|
@ -146,6 +147,7 @@ async def test_never_config(test_session, test_directory, async_client, test_wro
|
|||
for download in test_session.query(Download).all():
|
||||
test_session.delete(download)
|
||||
test_session.commit()
|
||||
config_versions_lost(test_session)
|
||||
subprocess.run(['rm', '-rf', str(test_directory / 'repos/missing')], check=True)
|
||||
|
||||
config.import_config()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import pytest
|
|||
|
||||
from modules.repos import lib
|
||||
from modules.repos.conftest import TEST_GIT_ENV
|
||||
from wrolpi.conftest import config_versions_lost
|
||||
from wrolpi.downloader import Download, DownloadStatus
|
||||
|
||||
|
||||
|
|
@ -395,6 +396,7 @@ async def test_clone_token_survives_the_config(test_session, async_client, git_r
|
|||
# Lose the database, restore it from the config.
|
||||
lib._delete_repository(test_session, repo)
|
||||
test_session.commit()
|
||||
config_versions_lost(test_session)
|
||||
config.import_config()
|
||||
test_session.expire_all()
|
||||
restored = test_session.query(lib.Repository).one()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import yaml
|
|||
|
||||
from modules.videos.lib import get_channels_config
|
||||
from modules.videos.models import Channel
|
||||
from wrolpi.conftest import config_was_imported
|
||||
from wrolpi.conftest import config_was_imported, config_versions_lost
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -319,6 +319,7 @@ class TestChannelsConfigEdgeCases:
|
|||
# Clear the file_format to simulate factory reset
|
||||
channel.collection.file_format = None
|
||||
test_session.commit()
|
||||
config_versions_lost(test_session)
|
||||
|
||||
# Re-import
|
||||
config.initialize()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue