MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / revert_changesets

Function revert_changesets

openlibrary/plugins/admin/code.py:102–121  ·  view source on GitHub ↗

An aggressive revert function ; it rolls back all the documents to the revision that existed before the changeset was applied. Note this means that any edits made _after_ the given changeset will also be lost.

(changeset_ids: Iterable[int], comment: str)

Source from the content-addressed store, hash-verified

100
101
102def revert_changesets(changeset_ids: Iterable[int], comment: str):
103 """
104 An aggressive revert function ; it rolls back all the documents to
105 the revision that existed before the changeset was applied.
106 Note this means that any edits made _after_ the given changeset will
107 also be lost.
108 """
109
110 def get_doc(key: str, revision: int) -> dict:
111 if revision == 0:
112 return {"key": key, "type": {"key": "/type/delete"}}
113 else:
114 return web.ctx.site.get(key, revision).dict()
115
116 site = web.ctx.site
117 docs = [get_doc(c["key"], c["revision"] - 1) for cid in changeset_ids for c in site.get_change(cid).changes]
118 docs = [doc for doc in docs if doc.get("type", {}).get("key") != "/type/delete"]
119 data = {"reverted_changesets": [str(cid) for cid in changeset_ids]}
120 manifest = web.ctx.site.save_many(docs, action="revert", data=data, comment=comment)
121 return manifest, len(docs)
122
123
124class admin(delegate.page):

Callers 3

revert_all_user_editsFunction · 0.85
POSTMethod · 0.85
POSTMethod · 0.85

Calls 5

lenFunction · 0.85
get_changeMethod · 0.80
get_docFunction · 0.70
getMethod · 0.45
save_manyMethod · 0.45

Tested by

no test coverage detected