Skip to content

Commit

Permalink
fix case where large prop queries were not being POSTed
Browse files Browse the repository at this point in the history
  • Loading branch information
fastily committed Dec 13, 2023
1 parent d6516ac commit 1e23143
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pwiki/mquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .ns import NS
from .query_constants import PropCont, PropNoCont, QConstant
from .query_utils import chunker, denormalize_result, get_continue_params, query_and_validate
from .utils import mine_for
from .utils import mine_for, PROP_TITLE_MAX

if TYPE_CHECKING:
from .wiki import Wiki
Expand Down Expand Up @@ -71,7 +71,7 @@ def _prop_no_cont(wiki: Wiki, titles: list[str], template: QConstant) -> dict:
out = dict.fromkeys(titles)

for chunk in chunker(titles, wiki.prop_title_max):
if response := query_and_validate(wiki, {**template.pl, "prop": template.name, "titles": "|".join(chunk)}, desc=f"peform a prop_no_cont query with '{template.name}'"):
if response := query_and_validate(wiki, {**template.pl, "prop": template.name, "titles": "|".join(chunk)}, len(chunk) > PROP_TITLE_MAX, f"peform a prop_no_cont query with '{template.name}'"):
for p in mine_for(response, "query", "pages"):
try:
out[p["title"]] = template.retrieve_results(p)
Expand Down
2 changes: 2 additions & 0 deletions pwiki/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from typing import Any

API_DEFAULTS = {"format": "json", "formatversion": "2"}
PROP_TITLE_MAX = 50
PROP_TITLE_MAX_BOT = 500

log = logging.getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions pwiki/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .oquery import OQuery
from .query_constants import MAX
from .query_utils import flatten_generator
from .utils import PROP_TITLE_MAX ,PROP_TITLE_MAX_BOT
from .waction import WAction
from .wparser import WikiText, WParser

Expand Down Expand Up @@ -73,11 +74,11 @@ def _refresh_rights(self) -> None:
if not self.username:
self.rights: list = []
self.is_bot: bool = False
self.prop_title_max: int = 50
self.prop_title_max: int = PROP_TITLE_MAX
else:
self.rights: list = self.list_user_rights()
self.is_bot: bool = "bot" in self.rights
self.prop_title_max: int = 500 if self.is_bot or "sysop" in self.rights else 50
self.prop_title_max: int = PROP_TITLE_MAX_BOT if self.is_bot or "sysop" in self.rights else PROP_TITLE_MAX

##################################################################################################
######################################## C O O K I E S ###########################################
Expand Down

0 comments on commit 1e23143

Please sign in to comment.