ArmindoFlores / ao3_api

An unofficial archiveofourown.org (AO3) API for python
MIT License
166 stars 64 forks source link

Loading the entire work should only be done when necessary #61

Open B-McDonnell opened 2 years ago

B-McDonnell commented 2 years ago

Currently, the work is loaded with view_full_work=true. For large works, this may cause unnecessary burden on both the user and the user and AO3. There are many instances where only the metadata is required, so why fetch the whole work?

I suggest the following system:

def reload(self, metadata_only=True):
    url = f"...&view_full_work={"false" if metadata_only else "true"}"
    self._fully_loaded = not metadata_only

Then, attributes that require the entire work will call reload(metadata_only=False) if not self._fully_loaded

# first chapter only attributes
authenticity_token
authors
bookmarks
categories
characters
comments
complete
date_edited
date_published
date_updated
expected_chapters
fandoms
hits
is_subscribed
kudos
language
metadata
nchapters
oneshot
rating
relationships
restricted
series
start_notes
status
summary
tags
title
url
warnings
words

# full work attributes
get_comments
get_images
end_notes
text

# first chapter only interactions
delete_bookmark
download
download_to_file
get_comments
get_images
is_subscribed
leave_kudos
unsubscribe

# entire work interactions
comment # I'm unsure here. Where do comments on the entire work go? The last chapter?
get_comments
get_images
load_chapters

Clearly, most of the time the entire work is not necessary, hence why I would make metadata_only default to true.