Skip to content

Instantly share code, notes, and snippets.

@efischer19
Created September 8, 2016 15:16
Show Gist options
  • Select an option

  • Save efischer19/3471fd87dc5b7366f23405ad87706cc7 to your computer and use it in GitHub Desktop.

Select an option

Save efischer19/3471fd87dc5b7366f23405ad87706cc7 to your computer and use it in GitHub Desktop.
Grades queries
<truncated, everything before this is "is the feature flag enabled" and "what's the data we're persisting" queries, nothing unusual>
The get_or_create logic begins here:
QUERY = u'SAVEPOINT "s140540290041600_x457"' - PARAMS = ()
select_related (read: INNER_JOIN) is attempted here, but since the object doesn't exist yet it does us no good:
QUERY = u'SELECT "grades_persistentsubsectiongrade"."created", "grades_persistentsubsectiongrade"."modified", "grades_persistentsubsectiongrade"."id", "grades_persistentsubsectiongrade"."user_id", "grades_persistentsubsectiongrade"."course_id", "grades_persistentsubsectiongrade"."usage_key", "grades_persistentsubsectiongrade"."subtree_edited_timestamp", "grades_persistentsubsectiongrade"."course_version", "grades_persistentsubsectiongrade"."earned_all", "grades_persistentsubsectiongrade"."possible_all", "grades_persistentsubsectiongrade"."earned_graded", "grades_persistentsubsectiongrade"."possible_graded", "grades_persistentsubsectiongrade"."visible_blocks_hash", "grades_visibleblocks"."id", "grades_visibleblocks"."blocks_json", "grades_visibleblocks"."hashed" FROM "grades_persistentsubsectiongrade" INNER JOIN "grades_visibleblocks" ON ( "grades_persistentsubsectiongrade"."visible_blocks_hash" = "grades_visibleblocks"."hashed" ) WHERE ("grades_persistentsubsectiongrade"."course_id" = %s AND "grades_persistentsubsectiongrade"."user_id" = %s AND "grades_persistentsubsectiongrade"."usage_key" = %s)' - PARAMS = (u'edx/course_44/run', 2, u'i4x://edx/course_44/problem/problem')
QUERY = u'SAVEPOINT "s140540290041600_x458"' - PARAMS = ()
QUERY = u'SAVEPOINT "s140540290041600_x459"' - PARAMS = ()
QUERY = u'SELECT "grades_visibleblocks"."id", "grades_visibleblocks"."blocks_json", "grades_visibleblocks"."hashed" FROM "grades_visibleblocks" WHERE "grades_visibleblocks"."hashed" = %s' - PARAMS = (u'SmAwfIgzmKT7XhDHaozkkdIAW9E=',)
QUERY = u'SAVEPOINT "s140540290041600_x460"' - PARAMS = ()
This is where we insert the data that *would* have been included in the select_related above:
QUERY = u'INSERT INTO "grades_visibleblocks" ("blocks_json", "hashed") VALUES (%s, %s)' - PARAMS = (u'[{"locator":"i4x://edx/course_44/problem/problem","max_score":0,"weight":null}]', u'SmAwfIgzmKT7XhDHaozkkdIAW9E=')
QUERY = u'RELEASE SAVEPOINT "s140540290041600_x460"' - PARAMS = ()
QUERY = u'RELEASE SAVEPOINT "s140540290041600_x459"' - PARAMS = ()
And here's where it gets linked to the "base" object in our get_or_create call:
QUERY = u'INSERT INTO "grades_persistentsubsectiongrade" ("created", "modified", "user_id", "course_id", "usage_key", "subtree_edited_timestamp", "course_version", "earned_all", "possible_all", "earned_graded", "possible_graded", "visible_blocks_hash") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' - PARAMS = (u'2016-09-08 15:01:44.743514', u'2016-09-08 15:01:44.743852', 2, u'edx/course_44/run', u'i4x://edx/course_44/problem/problem', u'2016-09-08 15:01:44.657000', u'', 0.0, 0.0, 0.0, 0.0, u'SmAwfIgzmKT7XhDHaozkkdIAW9E=')
QUERY = u'RELEASE SAVEPOINT "s140540290041600_x458"' - PARAMS = ()
QUERY = u'RELEASE SAVEPOINT "s140540290041600_x457"' - PARAMS = ()
Now here's the extra query
QUERY = u'SELECT "grades_visibleblocks"."id", "grades_visibleblocks"."blocks_json", "grades_visibleblocks"."hashed" FROM "grades_visibleblocks" WHERE "grades_visibleblocks"."hashed" = %s' - PARAMS = (u'SmAwfIgzmKT7XhDHaozkkdIAW9E=',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment