Skip to content

Commit

Permalink
updated Logical NOT restriction check
Browse files Browse the repository at this point in the history
Signed-off-by: Ernesto Soto <[email protected]>
  • Loading branch information
EStog committed Dec 2, 2019
1 parent 1ab8ce9 commit 09ce3e2
Show file tree
Hide file tree
Showing 6 changed files with 193,164 additions and 329,822 deletions.
2 changes: 1 addition & 1 deletion LICENCE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
QuantityEr: A program to obtain results amount of complex queries to GitHub.
Copyright (C) 2019-present Ernesto Soto Gómez.
Copyright (C) 2019-present Ernesto Soto Gómez.
Contact: <[email protected]>

This program is free software: you can redistribute it and/or modify
Expand Down
4 changes: 2 additions & 2 deletions code/lib/classes/internal/engines/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_total_amount(self, middle_code: MiddleCode) -> Tuple[int, int, int,
self._debug('Longest subquery', longest_subquery, header=middle_code.full_name)
longest_subquery_length = len(longest_subquery)
self._debug('Longest subquery length', longest_subquery_length, header=middle_code.full_name)
if not self._query_issuer.check_query_length(longest_subquery_length, middle_code.full_name):
if not self._query_issuer.check_query_restrictions(longest_subquery, middle_code.full_name):
self._debug('Subqueries that exceeds the maximum allowed length, will be discarded',
header=middle_code.full_name)
self._debug('Getting total amount of subqueries ...', header=middle_code.full_name)
Expand Down Expand Up @@ -147,7 +147,7 @@ def _run_simulation(self, subqueries_total, middle_code) -> Tuple[int, int, int,
if subquery not in self._cache:
self._debug('To issue', header=q.full_name)
to_issue_subqueries += 1
if not self._query_issuer.check_query_length(len(subquery), q.full_name):
if not self._query_issuer.check_query_restrictions(subquery, q.full_name):
self._debug(f'Subquery discarded', header=q.full_name)
else:
self._simulation_cache.add(subquery)
Expand Down
28 changes: 21 additions & 7 deletions code/lib/classes/internal/query_issuers/githubv3_query_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def verbose(func, message, arg=None):
func(message, arg, header=name)

verbose(self._debug, f'Getting results amount ...')
if not self.check_query_length(len(query), name):
if not self.check_query_restrictions(query, name):
verbose(self._debug, f'Subquery discarded')
return False, 0
delay = self._get_waiting_time()
Expand All @@ -111,15 +111,29 @@ def verbose(func, message, arg=None):
except GithubException as e:
verbose(self._query_critical, f'Error while issuing', e)

def check_query_length(self, query_length: int, name: str) -> bool:
if query_length > self._query_max_length:
def check_query_restrictions(self, query: str, name: str) -> bool:
query_len = len(query)
logical_not_amount = query.count('NOT ')
if query_len > self._query_max_length:
if self._admit_long_query:
self._warning(f'Maximum allowed length of {self._query_max_length} exceeded. Subquery length',
arg=query_length, header=name)
self._warning(f'Maximum allowed length of {self._query_max_length} exceeded. '
'Subquery length',
arg=query_len, header=name)
return False
else:
self._query_critical(f'Maximum allowed length of {self._query_max_length} exceeded. Subquery length',
arg=query_length, header=name)
self._query_critical(f'Maximum allowed length of {self._query_max_length} exceeded. '
f'Subquery length',
arg=query_len, header=name)
elif logical_not_amount > 5:
if self._admit_long_query:
self._warning(f'Maximum allowed logical NOT amount of 5 exceeded. '
f'Logical NOT amount',
arg=logical_not_amount, header=name)
return False
else:
self._query_critical(f'Maximum allowed logical NOT amount of 5 exceeded. '
f'Logical NOT amount',
arg=logical_not_amount, header=name)
else:
return True

Expand Down
2 changes: 1 addition & 1 deletion code/lib/classes/internal/query_issuers/query_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def issue(self, name: str, query: str) -> Tuple[bool, int]:
pass

@abstractmethod
def check_query_length(self, query_length: int, name: str) -> bool:
def check_query_restrictions(self, query: str, name: str) -> bool:
pass

@abstractmethod
Expand Down
Loading

0 comments on commit 09ce3e2

Please sign in to comment.