mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 22:54:27 -04:00
remove atomic transactions
This commit is contained in:
parent
844b5c5e20
commit
1cabde3ccd
1 changed files with 27 additions and 19 deletions
|
@ -23,9 +23,11 @@ def parse_sql_main_index(out_dir: Path=OUTPUT_DIR) -> Iterator[Link]:
|
||||||
)
|
)
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
def remove_from_sql_main_index(snapshots: QuerySet, out_dir: Path=OUTPUT_DIR) -> None:
|
def remove_from_sql_main_index(snapshots: QuerySet, atomic: bool=False, out_dir: Path=OUTPUT_DIR) -> None:
|
||||||
with transaction.atomic():
|
if atomic:
|
||||||
snapshots.delete()
|
with transaction.atomic():
|
||||||
|
return snapshots.delete()
|
||||||
|
return snapshots.delete()
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
def write_link_to_sql_index(link: Link):
|
def write_link_to_sql_index(link: Link):
|
||||||
|
@ -41,7 +43,7 @@ def write_link_to_sql_index(link: Link):
|
||||||
while Snapshot.objects.filter(timestamp=info["timestamp"]).exists():
|
while Snapshot.objects.filter(timestamp=info["timestamp"]).exists():
|
||||||
info["timestamp"] = str(float(info["timestamp"]) + 1.0)
|
info["timestamp"] = str(float(info["timestamp"]) + 1.0)
|
||||||
|
|
||||||
snapshot, _ = Snapshot.objects.update_or_create(url=link.url, defaults=info)
|
snapshot, _ = Snapshot.objects.update_or_create(url=link.url, defaults=info)
|
||||||
snapshot.save_tags(tags)
|
snapshot.save_tags(tags)
|
||||||
|
|
||||||
for extractor, entries in link.history.items():
|
for extractor, entries in link.history.items():
|
||||||
|
@ -80,29 +82,35 @@ def write_link_to_sql_index(link: Link):
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
def write_sql_main_index(links: List[Link], out_dir: Path=OUTPUT_DIR) -> None:
|
def write_sql_main_index(links: List[Link], out_dir: Path=OUTPUT_DIR) -> None:
|
||||||
with transaction.atomic():
|
for link in links:
|
||||||
for link in links:
|
# with transaction.atomic():
|
||||||
write_link_to_sql_index(link)
|
# write_link_to_sql_index(link)
|
||||||
|
write_link_to_sql_index(link)
|
||||||
|
|
||||||
|
|
||||||
@enforce_types
|
@enforce_types
|
||||||
def write_sql_link_details(link: Link, out_dir: Path=OUTPUT_DIR) -> None:
|
def write_sql_link_details(link: Link, out_dir: Path=OUTPUT_DIR) -> None:
|
||||||
from core.models import Snapshot
|
from core.models import Snapshot
|
||||||
|
|
||||||
with transaction.atomic():
|
# with transaction.atomic():
|
||||||
try:
|
# try:
|
||||||
snap = Snapshot.objects.get(url=link.url)
|
# snap = Snapshot.objects.get(url=link.url)
|
||||||
except Snapshot.DoesNotExist:
|
# except Snapshot.DoesNotExist:
|
||||||
snap = write_link_to_sql_index(link)
|
# snap = write_link_to_sql_index(link)
|
||||||
snap.title = link.title
|
# snap.title = link.title
|
||||||
|
try:
|
||||||
|
snap = Snapshot.objects.get(url=link.url)
|
||||||
|
except Snapshot.DoesNotExist:
|
||||||
|
snap = write_link_to_sql_index(link)
|
||||||
|
snap.title = link.title
|
||||||
|
|
||||||
tag_set = (
|
tag_set = (
|
||||||
set(tag.strip() for tag in (link.tags or '').split(','))
|
set(tag.strip() for tag in (link.tags or '').split(','))
|
||||||
)
|
)
|
||||||
tag_list = list(tag_set) or []
|
tag_list = list(tag_set) or []
|
||||||
|
|
||||||
snap.save()
|
snap.save()
|
||||||
snap.save_tags(tag_list)
|
snap.save_tags(tag_list)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue