Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Conversation

ara4n
Copy link
Member

@ara4n ara4n commented Mar 13, 2018

No description provided.

@ara4n ara4n changed the title fix bug #2926 (loading all state for a given key from the DB if the state_key is None) fix bug #2926 (loading all state for a given type from the DB if the state_key is None) Mar 13, 2018
else:
where_clause += "(type = ? AND state_key = ?)"
where_args.extend([typ[0], typ[1]])
if typ != types[-1]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this supposed to be checking if it's the last element? it looks fragile.

Why not do " OR ".join(where_clauses), or something

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is. guess it is fragile if you have dups in the list. stupid brainfart on .join(where_clauses)

) if state_key is not None else
(
"AND type = ?",
(etype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a ,

@@ -240,6 +240,10 @@ def _get_state_groups_from_groups_txn(self, txn, groups, types=None):
(
"AND type = ? AND state_key = ?",
(etype, state_key)
) if state_key is not None else
(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably put this on the previous line after the else

@ara4n
Copy link
Member Author

ara4n commented Mar 13, 2018

@richvdh ptal

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to remove the optimisation at line 307 (or at least make it understand about state_key is None)

@@ -259,10 +262,17 @@ def _get_state_groups_from_groups_txn(self, txn, groups, types=None):
key = (typ, state_key)
results[group][key] = event_id
else:
where_args = []
where_clauses = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be nice to define this inside the if clause where it is used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i may be going insane, but i'm failing to see why? it's used outside the if clause, so isn't it nicer to define it at the 'right' scope level, rather than give the impression that it's scoped to the if block (even though python scoping extends to the whole def?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be going insane, but I can't see it being used outside the if clause?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surely where_args & where_clauses are used much later on to actually execute the query. hence defining them at the scope common to both. or are we talking about different if clauses?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about where_clauses, which is used at lines 270, 273 and 275. They are all inside the next if clause.

if types is not None:
for typ in types:
if typ[1] is None:
where_clauses.append("(type = ?)")
where_args.extend(typ[0])
else:
where_clauses.append("(type = ? AND state_key = ?)")
where_args.extend([typ[0], typ[1]])
where_clause = "AND (%s)" % (" OR ".join(where_clauses))

@@ -279,7 +289,7 @@ def _get_state_groups_from_groups_txn(self, txn, groups, types=None):
# after we finish deduping state, which requires this func)
args = [next_group]
if types:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be unconditional now:

args = [next_group] + where_args

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, although unclear what that buys us? (plus in my lazyloading PR we do have other if's at that point)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplicity, mostly. but I agree it's not a big deal.

@richvdh richvdh assigned ara4n and unassigned richvdh and erikjohnston Mar 13, 2018
@ara4n
Copy link
Member Author

ara4n commented Mar 13, 2018

I am totally failing to understand the optimisation at line 307 - the level of golf here is impenetrable :|

when type filter includes wildcards on state_key
@ara4n
Copy link
Member Author

ara4n commented Mar 13, 2018

okay, it finally clicked; have made the comments more idiot-proof and hopefully disabled the optimisation correctly; good catch.

@richvdh ptal

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still gunning for moving where_clauses inside the if, but lgtm either way

@ara4n ara4n merged commit d144ed6 into develop Mar 13, 2018
@richvdh richvdh changed the title fix bug #2926 (loading all state for a given type from the DB if the state_key is None) fix bug #2969 (loading all state for a given type from the DB if the state_key is None) Jun 6, 2018
@hawkowl hawkowl deleted the matthew/fix_2969 branch September 20, 2018 13:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants