desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Gets the current retry timings (if any) for a given destination.
Args:
destination (str)
Returns:
None if not retrying
Otherwise a dict for the retry scheme'
| @cached(max_entries=10000)
def get_destination_retry_timings(self, destination):
| return self.runInteraction('get_destination_retry_timings', self._get_destination_retry_timings, destination)
|
'Sets the current retry timings for a given destination.
Both timings should be zero if retrying is no longer occuring.
Args:
destination (str)
retry_last_ts (int) - time of last retry attempt in unix epoch ms
retry_interval (int) - how long until next retry in ms'
| def set_destination_retry_timings(self, destination, retry_last_ts, retry_interval):
| return self.runInteraction('set_destination_retry_timings', self._set_destination_retry_timings, destination, retry_last_ts, retry_interval)
|
'Get all destinations which are due a retry for sending a transaction.
Returns:
list: A list of dicts'
| def get_destinations_needing_retry(self):
| return self.runInteraction('get_destinations_needing_retry', self._get_destinations_needing_retry)
|
'Performs a full text search over events with given keys.
Args:
room_ids (list): List of room ids to search in
search_term (str): Search term to search for
keys (list): List of keys to search in, currently supports
"content.body", "content.name", "content.topic"
Returns:
list of dicts'
| @defer.inlineCallbacks
def search_msgs(self, room_ids, search_term, keys):
| clauses = []
search_query = search_query = _parse_query(self.database_engine, search_term)
args = []
if (len(room_ids) < 500):
clauses.append(('room_id IN (%s)' % (','.join((['?'] * len(room_ids))),)))
args.extend(room_ids)
local_clauses = []
for key in keys:
local_... |
'Performs a full text search over events with given keys.
Args:
room_id (list): The room_ids to search in
search_term (str): Search term to search for
keys (list): List of keys to search in, currently supports
"content.body", "content.name", "content.topic"
pagination_token (str): A pagination token previously returned... | @defer.inlineCallbacks
def search_rooms(self, room_ids, search_term, keys, limit, pagination_token=None):
| clauses = []
search_query = search_query = _parse_query(self.database_engine, search_term)
args = []
if (len(room_ids) < 500):
clauses.append(('room_id IN (%s)' % (','.join((['?'] * len(room_ids))),)))
args.extend(room_ids)
local_clauses = []
for key in keys:
local_... |
'Given a list of events and a search term, return a list of words
that match from the content of the event.
This is used to give a list of words that clients can match against to
highlight the matching parts.
Args:
search_query (str)
events (list): A list of events
Returns:
deferred : A set of strings.'
| def _find_highlights_in_postgres(self, search_query, events):
| def f(txn):
highlight_words = set()
for event in events:
values = []
for key in ('body', 'name', 'topic'):
v = event.content.get(key, None)
if v:
values.append(v)
if (not values):
continue
... |
'Check if the room is either world_readable or publically joinable'
| @cachedInlineCallbacks(cache_context=True)
def is_room_world_readable_or_publicly_joinable(self, room_id, cache_context):
| current_state_ids = (yield self.get_current_state_ids(room_id, on_invalidate=cache_context.invalidate))
join_rules_id = current_state_ids.get((EventTypes.JoinRules, ''))
if join_rules_id:
join_rule_ev = (yield self.get_event(join_rules_id, allow_none=True))
if join_rule_ev:
if (j... |
'Add user to the list of users in public rooms
Args:
room_id (str): A room_id that all users are in that is world_readable
or publically joinable
user_ids (list(str)): Users to add'
| @defer.inlineCallbacks
def add_users_to_public_room(self, room_id, user_ids):
| (yield self._simple_insert_many(table='users_in_pubic_room', values=[{'user_id': user_id, 'room_id': room_id} for user_id in user_ids], desc='add_users_to_public_room'))
for user_id in user_ids:
self.get_user_in_public_room.invalidate((user_id,))
|
'Add profiles to the user directory
Args:
room_id (str): A room_id that all users are joined to
users_with_profile (dict): Users to add to directory in the form of
mapping of user_id -> ProfileInfo'
| def add_profiles_to_user_dir(self, room_id, users_with_profile):
| if isinstance(self.database_engine, PostgresEngine):
sql = "\n INSERT INTO user_directory_search(user_id, vector)\n VALUES (?,\n ... |
'Get all user_ids that are in the room directory becuase they\'re
in the given room_id'
| def get_users_in_public_due_to_room(self, room_id):
| return self._simple_select_onecol(table='users_in_pubic_room', keyvalues={'room_id': room_id}, retcol='user_id', desc='get_users_in_public_due_to_room')
|
'Get all user_ids that are in the room directory becuase they\'re
in the given room_id'
| @defer.inlineCallbacks
def get_users_in_dir_due_to_room(self, room_id):
| user_ids_dir = (yield self._simple_select_onecol(table='user_directory', keyvalues={'room_id': room_id}, retcol='user_id', desc='get_users_in_dir_due_to_room'))
user_ids_pub = (yield self._simple_select_onecol(table='users_in_pubic_room', keyvalues={'room_id': room_id}, retcol='user_id', desc='get_users_in_dir_... |
'Get all room_ids we\'ve ever known about, in ascending order of "size"'
| @defer.inlineCallbacks
def get_all_rooms(self):
| sql = '\n SELECT room_id FROM current_state_events\n GROUP BY room_id\n ORDER BY count(*) ASC\n '
rows = (yield self... |
'Insert entries into the users_who_share_rooms table. The first
user should be a local user.
Args:
room_id (str)
share_private (bool): Is the room private
user_id_tuples([(str, str)]): iterable of 2-tuple of user IDs.'
| def add_users_who_share_room(self, room_id, share_private, user_id_tuples):
| def _add_users_who_share_room_txn(txn):
self._simple_insert_many_txn(txn, table='users_who_share_rooms', values=[{'user_id': user_id, 'other_user_id': other_user_id, 'room_id': room_id, 'share_private': share_private} for (user_id, other_user_id) in user_id_tuples])
for (user_id, other_user_id) in u... |
'Updates entries in the users_who_share_rooms table. The first
user should be a local user.
Args:
room_id (str)
share_private (bool): Is the room private
user_id_tuples([(str, str)]): iterable of 2-tuple of user IDs.'
| def update_users_who_share_room(self, room_id, share_private, user_id_sets):
| def _update_users_who_share_room_txn(txn):
sql = '\n UPDATE users_who_share_rooms\n SET room_id = ?, share_private = ?\n ... |
'Deletes entries in the users_who_share_rooms table. The first
user should be a local user.
Args:
room_id (str)
share_private (bool): Is the room private
user_id_tuples([(str, str)]): iterable of 2-tuple of user IDs.'
| def remove_user_who_share_room(self, user_id, other_user_id):
| def _remove_user_who_share_room_txn(txn):
self._simple_delete_txn(txn, table='users_who_share_rooms', keyvalues={'user_id': user_id, 'other_user_id': other_user_id})
txn.call_after(self.get_users_who_share_room_from_dir.invalidate, (user_id,))
txn.call_after(self.get_if_users_share_a_room.in... |
'Gets if users share a room.
Args:
user_id (str): Must be a local user_id
other_user_id (str)
Returns:
bool|None: None if they don\'t share a room, otherwise whether they
share a private room or not.'
| @cached(max_entries=500000)
def get_if_users_share_a_room(self, user_id, other_user_id):
| return self._simple_select_one_onecol(table='users_who_share_rooms', keyvalues={'user_id': user_id, 'other_user_id': other_user_id}, retcol='share_private', allow_none=True, desc='get_if_users_share_a_room')
|
'Returns the set of users who share a room with `user_id`
Args:
user_id(str): Must be a local user
Returns:
dict: user_id -> share_private mapping'
| @cachedInlineCallbacks(max_entries=500000, iterable=True)
def get_users_who_share_room_from_dir(self, user_id):
| rows = (yield self._simple_select_list(table='users_who_share_rooms', keyvalues={'user_id': user_id}, retcols=('other_user_id', 'share_private'), desc='get_users_who_share_room_with_user'))
defer.returnValue({row['other_user_id']: row['share_private'] for row in rows})
|
'Get all user tuples that are in the users_who_share_rooms due to the
given room_id.
Returns:
[(user_id, other_user_id)]: where one of the two will match the given
user_id.'
| def get_users_in_share_dir_with_room_id(self, user_id, room_id):
| sql = '\n SELECT user_id, other_user_id FROM users_who_share_rooms\n WHERE room_id = ? AND (user_id = ? OR other_user_id = ?)\n '
return self.... |
'Given two user_ids find out the list of rooms they share.'
| @defer.inlineCallbacks
def get_rooms_in_common_for_users(self, user_id, other_user_id):
| sql = "\n SELECT room_id FROM (\n SELECT c.room_id FROM current_state_events AS c\n INNER JOIN room_memberships ... |
'Delete the entire user directory'
| def delete_all_from_user_dir(self):
| def _delete_all_from_user_dir_txn(txn):
txn.execute('DELETE FROM user_directory')
txn.execute('DELETE FROM user_directory_search')
txn.execute('DELETE FROM users_in_pubic_room')
txn.execute('DELETE FROM users_who_share_rooms')
txn.call_after(self.get_u... |
'Searches for users in directory
Returns:
dict of the form::
"limited": <bool>, # whether there were more results or not
"results": [ # Ordered by best match first
"user_id": <user_id>,
"display_name": <display_name>,
"avatar_url": <avatar_url>'
| @defer.inlineCallbacks
def search_user_dir(self, user_id, search_term, limit):
| if isinstance(self.database_engine, PostgresEngine):
(full_query, exact_query, prefix_query) = _parse_query_postgres(search_term)
sql = "\n SELECT d.user_id, display_name, avatar_url\n ... |
'Update the stats after doing an update'
| def update(self, item_count, duration_ms):
| self.total_item_count += item_count
self.total_duration_ms += duration_ms
self.avg_item_count += (0.1 * (item_count - self.avg_item_count))
self.avg_duration_ms += (0.1 * (duration_ms - self.avg_duration_ms))
|
'An estimate of how long it takes to do a single update.
Returns:
A duration in ms as a float'
| def average_items_per_ms(self):
| if (self.total_item_count == 0):
return None
else:
return (float(self.avg_item_count) / float(self.avg_duration_ms))
|
'An estimate of how long it takes to do a single update.
Returns:
A duration in ms as a float'
| def total_items_per_ms(self):
| if (self.total_item_count == 0):
return None
else:
return (float(self.total_item_count) / float(self.total_duration_ms))
|
'Does some amount of work on the next queued background update
Args:
desired_duration_ms(float): How long we want to spend
updating.
Returns:
A deferred that completes once some amount of work is done.
The deferred will have a value of None if there is currently
no more work to do.'
| @defer.inlineCallbacks
def do_next_background_update(self, desired_duration_ms):
| if (not self._background_update_queue):
updates = (yield self._simple_select_list('background_updates', keyvalues=None, retcols=('update_name', 'depends_on')))
in_flight = set((update['update_name'] for update in updates))
for update in updates:
if (update['depends_on'] not in in... |
'Register a handler for doing a background update.
The handler should take two arguments:
* A dict of the current progress
* An integer count of the number of items to update in this batch.
The handler should return a deferred integer count of items updated.
The hander is responsible for updating the progress of the up... | def register_background_update_handler(self, update_name, update_handler):
| self._background_update_handlers[update_name] = update_handler
|
'Helper for store classes to do a background index addition
To use:
1. use a schema delta file to add a background update. Example:
INSERT INTO background_updates (update_name, progress_json) VALUES
(\'my_new_index\', \'{}\');
2. In the Store constructor, call this method
Args:
update_name (str): update_name to registe... | def register_background_index_update(self, update_name, index_name, table, columns, where_clause=None, unique=False, psql_only=False):
| def create_index_psql(conn):
conn.rollback()
conn.set_session(autocommit=True)
try:
c = conn.cursor()
sql = ('DROP INDEX IF EXISTS %s' % (index_name,))
logger.debug('[SQL] %s', sql)
c.execute(sql)
sql = ('CREATE %(... |
'Starts a background update running.
Args:
update_name: The update to set running.
progress: The initial state of the progress of the update.
Returns:
A deferred that completes once the task has been added to the
queue.'
| def start_background_update(self, update_name, progress):
| self._background_update_queue = []
progress_json = json.dumps(progress)
return self._simple_insert('background_updates', {'update_name': update_name, 'progress_json': progress_json})
|
'Removes a completed background update task from the queue.
Args:
update_name(str): The name of the completed task to remove
Returns:
A deferred that completes once the task is removed.'
| def _end_background_update(self, update_name):
| self._background_update_queue = [name for name in self._background_update_queue if (name != update_name)]
return self._simple_delete_one('background_updates', keyvalues={'update_name': update_name})
|
'Update the progress of a background update
Args:
txn(cursor): The transaction.
update_name(str): The name of the background update task
progress(dict): The progress of the update.'
| def _background_update_progress_txn(self, txn, update_name, progress):
| progress_json = json.dumps(progress)
self._simple_update_one_txn(txn, 'background_updates', keyvalues={'update_name': update_name}, updatevalues={'progress_json': progress_json})
|
'Call the given callback on the main twisted thread after the
transaction has finished. Used to invalidate the caches on the
correct thread.'
| def call_after(self, callback, *args, **kwargs):
| self.after_callbacks.append((callback, args, kwargs))
|
'Strip newlines out of SQL so that the loggers in the DB are on one line'
| def _make_sql_one_line(self, sql):
| return ' '.join((l.strip() for l in sql.splitlines() if l.strip()))
|
'Wraps the .runInteraction() method on the underlying db_pool.'
| @defer.inlineCallbacks
def runInteraction(self, desc, func, *args, **kwargs):
| current_context = LoggingContext.current_context()
start_time = (time.time() * 1000)
after_callbacks = []
final_callbacks = []
def inner_func(conn, *args, **kwargs):
with LoggingContext('runInteraction') as context:
sql_scheduling_timer.inc_by(((time.time() * 1000) - start_time))... |
'Wraps the .runInteraction() method on the underlying db_pool.'
| @defer.inlineCallbacks
def runWithConnection(self, func, *args, **kwargs):
| current_context = LoggingContext.current_context()
start_time = (time.time() * 1000)
def inner_func(conn, *args, **kwargs):
with LoggingContext('runWithConnection') as context:
sql_scheduling_timer.inc_by(((time.time() * 1000) - start_time))
if self.database_engine.is_connect... |
'Converts a SQL cursor into an list of dicts.
Args:
cursor : The DBAPI cursor which has executed a query.
Returns:
A list of dicts where the key is the column header.'
| @staticmethod
def cursor_to_dict(cursor):
| col_headers = list((intern(column[0]) for column in cursor.description))
results = list((dict(zip(col_headers, row)) for row in cursor))
return results
|
'Runs a single query for a result set.
Args:
decoder - The function which can resolve the cursor results to
something meaningful.
query - The query string to execute
*args - Query args.
Returns:
The result of decoder(results)'
| def _execute(self, desc, decoder, query, *args):
| def interaction(txn):
txn.execute(query, args)
if decoder:
return decoder(txn)
else:
return txn.fetchall()
return self.runInteraction(desc, interaction)
|
'Executes an INSERT query on the named table.
Args:
table : string giving the table name
values : dict of new column names and values for them
Returns:
bool: Whether the row was inserted or not. Only useful when
`or_ignore` is True'
| @defer.inlineCallbacks
def _simple_insert(self, table, values, or_ignore=False, desc='_simple_insert'):
| try:
(yield self.runInteraction(desc, self._simple_insert_txn, table, values))
except self.database_engine.module.IntegrityError:
if (not or_ignore):
raise
defer.returnValue(False)
defer.returnValue(True)
|
'Args:
table (str): The table to upsert into
keyvalues (dict): The unique key tables and their new values
values (dict): The nonunique columns and their new values
insertion_values (dict): key/values to use when inserting
Returns:
Deferred(bool): True if a new entry was created, False if an
existing one was updated.'
| def _simple_upsert(self, table, keyvalues, values, insertion_values={}, desc='_simple_upsert', lock=True):
| return self.runInteraction(desc, self._simple_upsert_txn, table, keyvalues, values, insertion_values, lock)
|
'Executes a SELECT query on the named table, which is expected to
return a single row, returning a single column from it.
Args:
table : string giving the table name
keyvalues : dict of column names and values to select the row with
retcols : list of strings giving the names of the columns to return
allow_none : If true... | def _simple_select_one(self, table, keyvalues, retcols, allow_none=False, desc='_simple_select_one'):
| return self.runInteraction(desc, self._simple_select_one_txn, table, keyvalues, retcols, allow_none)
|
'Executes a SELECT query on the named table, which is expected to
return a single row, returning a single column from it.
Args:
table : string giving the table name
keyvalues : dict of column names and values to select the row with
retcol : string giving the name of the column to return'
| def _simple_select_one_onecol(self, table, keyvalues, retcol, allow_none=False, desc='_simple_select_one_onecol'):
| return self.runInteraction(desc, self._simple_select_one_onecol_txn, table, keyvalues, retcol, allow_none=allow_none)
|
'Executes a SELECT query on the named table, which returns a list
comprising of the values of the named column from the selected rows.
Args:
table (str): table name
keyvalues (dict): column names and values to select the rows with
retcol (str): column whos value we wish to retrieve.
Returns:
Deferred: Results in a list... | def _simple_select_onecol(self, table, keyvalues, retcol, desc='_simple_select_onecol'):
| return self.runInteraction(desc, self._simple_select_onecol_txn, table, keyvalues, retcol)
|
'Executes a SELECT query on the named table, which may return zero or
more rows, returning the result as a list of dicts.
Args:
table (str): the table name
keyvalues (dict[str, Any] | None):
column names and values to select the rows with, or None to not
apply a WHERE clause.
retcols (iterable[str]): the names of the c... | def _simple_select_list(self, table, keyvalues, retcols, desc='_simple_select_list'):
| return self.runInteraction(desc, self._simple_select_list_txn, table, keyvalues, retcols)
|
'Executes a SELECT query on the named table, which may return zero or
more rows, returning the result as a list of dicts.
Args:
txn : Transaction object
table (str): the table name
keyvalues (dict[str, T] | None):
column names and values to select the rows with, or None to not
apply a WHERE clause.
retcols (iterable[st... | @classmethod
def _simple_select_list_txn(cls, txn, table, keyvalues, retcols):
| if keyvalues:
sql = ('SELECT %s FROM %s WHERE %s' % (', '.join(retcols), table, ' AND '.join((('%s = ?' % (k,)) for k in keyvalues))))
txn.execute(sql, keyvalues.values())
else:
sql = ('SELECT %s FROM %s' % (', '.join(retcols), table))
tx... |
'Executes a SELECT query on the named table, which may return zero or
more rows, returning the result as a list of dicts.
Filters rows by if value of `column` is in `iterable`.
Args:
table : string giving the table name
column : column name to test for inclusion against `iterable`
iterable : list
keyvalues : dict of co... | @defer.inlineCallbacks
def _simple_select_many_batch(self, table, column, iterable, retcols, keyvalues={}, desc='_simple_select_many_batch', batch_size=100):
| results = []
if (not iterable):
defer.returnValue(results)
chunks = [iterable[i:(i + batch_size)] for i in xrange(0, len(iterable), batch_size)]
for chunk in chunks:
rows = (yield self.runInteraction(desc, self._simple_select_many_txn, table, column, chunk, keyvalues, retcols))
r... |
'Executes a SELECT query on the named table, which may return zero or
more rows, returning the result as a list of dicts.
Filters rows by if value of `column` is in `iterable`.
Args:
txn : Transaction object
table : string giving the table name
column : column name to test for inclusion against `iterable`
iterable : li... | @classmethod
def _simple_select_many_txn(cls, txn, table, column, iterable, keyvalues, retcols):
| if (not iterable):
return []
sql = ('SELECT %s FROM %s' % (', '.join(retcols), table))
clauses = []
values = []
clauses.append(('%s IN (%s)' % (column, ','.join(('?' for _ in iterable)))))
values.extend(iterable)
for (key, value) in keyvalues.iteritems():
cl... |
'Executes an UPDATE query on the named table, setting new values for
columns in a row matching the key values.
Args:
table : string giving the table name
keyvalues : dict of column names and values to select the row with
updatevalues : dict giving column names and values to update
retcols : optional list of column name... | def _simple_update_one(self, table, keyvalues, updatevalues, desc='_simple_update_one'):
| return self.runInteraction(desc, self._simple_update_one_txn, table, keyvalues, updatevalues)
|
'Executes a DELETE query on the named table, expecting to delete a
single row.
Args:
table : string giving the table name
keyvalues : dict of column names and values to select the row with'
| def _simple_delete_one(self, table, keyvalues, desc='_simple_delete_one'):
| return self.runInteraction(desc, self._simple_delete_one_txn, table, keyvalues)
|
'Executes a DELETE query on the named table, expecting to delete a
single row.
Args:
table : string giving the table name
keyvalues : dict of column names and values to select the row with'
| @staticmethod
def _simple_delete_one_txn(txn, table, keyvalues):
| sql = ('DELETE FROM %s WHERE %s' % (table, ' AND '.join((('%s = ?' % (k,)) for k in keyvalues))))
txn.execute(sql, keyvalues.values())
if (txn.rowcount == 0):
raise StoreError(404, 'No row found')
if (txn.rowcount > 1):
raise StoreError(500, 'more than ... |
'Executes a DELETE query on the named table.
Filters rows by if value of `column` is in `iterable`.
Args:
txn : Transaction object
table : string giving the table name
column : column name to test for inclusion against `iterable`
iterable : list
keyvalues : dict of column names and values to select the rows with'
| @staticmethod
def _simple_delete_many_txn(txn, table, column, iterable, keyvalues):
| if (not iterable):
return
sql = ('DELETE FROM %s' % table)
clauses = []
values = []
clauses.append(('%s IN (%s)' % (column, ','.join(('?' for _ in iterable)))))
values.extend(iterable)
for (key, value) in keyvalues.iteritems():
clauses.append(('%s = ?' % (ke... |
'Invalidates the cache and adds it to the cache stream so slaves
will know to invalidate their caches.
This should only be used to invalidate caches where slaves won\'t
otherwise know from other replication streams that the cache should
be invalidated.'
| def _invalidate_cache_and_stream(self, txn, cache_func, keys):
| txn.call_after(cache_func.invalidate, keys)
if isinstance(self.database_engine, PostgresEngine):
ctx = self._cache_id_gen.get_next()
stream_id = ctx.__enter__()
txn.call_finally(ctx.__exit__, None, None, None)
txn.call_after(self.hs.get_notifier().on_new_replication_data)
... |
'Executes a SELECT query on the named table with start and limit,
of row numbers, which may return zero or number of rows from start to limit,
returning the result as a list of dicts.
Args:
table (str): the table name
keyvalues (dict[str, Any] | None):
column names and values to select the rows with, or None to not
app... | def _simple_select_list_paginate(self, table, keyvalues, pagevalues, retcols, desc='_simple_select_list_paginate'):
| return self.runInteraction(desc, self._simple_select_list_paginate_txn, table, keyvalues, pagevalues, retcols)
|
'Executes a SELECT query on the named table with start and limit,
of row numbers, which may return zero or number of rows from start to limit,
returning the result as a list of dicts.
Args:
txn : Transaction object
table (str): the table name
keyvalues (dict[str, T] | None):
column names and values to select the rows w... | @classmethod
def _simple_select_list_paginate_txn(cls, txn, table, keyvalues, pagevalues, retcols):
| if keyvalues:
sql = ('SELECT %s FROM %s WHERE %s ORDER BY %s' % (', '.join(retcols), table, ' AND '.join((('%s = ?' % (k,)) for k in keyvalues)), ' ? ASC LIMIT ? OFFSET ?'))
txn.execute(sql, (keyvalues.values() + pagevalues))
else:
... |
'Get a list of users from start row to a limit number of rows. This will
return a json object with users and total number of users in users list.
Args:
table (str): the table name
keyvalues (dict[str, Any] | None):
column names and values to select the rows with, or None to not
apply a WHERE clause.
pagevalues ([]):
or... | @defer.inlineCallbacks
def get_user_list_paginate(self, table, keyvalues, pagevalues, retcols, desc='get_user_list_paginate'):
| users = (yield self.runInteraction(desc, self._simple_select_list_paginate_txn, table, keyvalues, pagevalues, retcols))
count = (yield self.runInteraction(desc, self.get_user_count_txn))
retval = {'users': users, 'total': count}
defer.returnValue(retval)
|
'Get a total number of registerd users in the users list.
Args:
txn : Transaction object
Returns:
defer.Deferred: resolves to int'
| def get_user_count_txn(self, txn):
| sql_count = 'SELECT COUNT(*) FROM users WHERE is_guest = 0;'
txn.execute(sql_count)
count = txn.fetchone()[0]
defer.returnValue(count)
|
'Executes a SELECT query on the named table, which may return zero or
more rows, returning the result as a list of dicts.
Args:
table (str): the table name
term (str | None):
term for searching the table matched to a column.
col (str): column to query term should be matched to
retcols (iterable[str]): the names of the ... | def _simple_search_list(self, table, term, col, retcols, desc='_simple_search_list'):
| return self.runInteraction(desc, self._simple_search_list_txn, table, term, col, retcols)
|
'Executes a SELECT query on the named table, which may return zero or
more rows, returning the result as a list of dicts.
Args:
txn : Transaction object
table (str): the table name
term (str | None):
term for searching the table matched to a column.
col (str): column to query term should be matched to
retcols (iterable... | @classmethod
def _simple_search_list_txn(cls, txn, table, term, col, retcols):
| if term:
sql = ('SELECT %s FROM %s WHERE %s LIKE ?' % (', '.join(retcols), table, col))
termvalues = [(('%%' + term) + '%%')]
txn.execute(sql, termvalues)
else:
return 0
return cls.cursor_to_dict(txn)
|
'Args:
event: the event set actions for
tuples: list of tuples of (user_id, actions)'
| def _set_push_actions_for_event_and_users_txn(self, txn, event, tuples):
| values = []
for (uid, actions) in tuples:
is_highlight = (1 if _action_has_highlight(actions) else 0)
values.append({'room_id': event.room_id, 'event_id': event.event_id, 'user_id': uid, 'actions': _serialize_action(actions, is_highlight), 'stream_ordering': event.internal_metadata.stream_orderi... |
'Get a list of the most recent unread push actions for a given user,
within the given stream ordering range. Called by the httppusher.
Args:
user_id (str): The user to fetch push actions for.
min_stream_ordering(int): The exclusive lower bound on the
stream ordering of event push actions to fetch.
max_stream_ordering(i... | @defer.inlineCallbacks
def get_unread_push_actions_for_user_in_range_for_http(self, user_id, min_stream_ordering, max_stream_ordering, limit=20):
| def get_after_receipt(txn):
sql = "SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions, ep.highlight FROM ( SELECT room_id, MAX(topological_ordering) as topological_ordering, MAX(stream_orde... |
'Get a list of the most recent unread push actions for a given user,
within the given stream ordering range. Called by the emailpusher
Args:
user_id (str): The user to fetch push actions for.
min_stream_ordering(int): The exclusive lower bound on the
stream ordering of event push actions to fetch.
max_stream_ordering(i... | @defer.inlineCallbacks
def get_unread_push_actions_for_user_in_range_for_email(self, user_id, min_stream_ordering, max_stream_ordering, limit=20):
| def get_after_receipt(txn):
sql = "SELECT ep.event_id, ep.room_id, ep.stream_ordering, ep.actions, ep.highlight, e.received_ts FROM ( SELECT room_id, MAX(topological_ordering) as topological_ordering, MAX(s... |
'Purges old push actions for a user and room before a given
topological_ordering.
We however keep a months worth of highlighted notifications, so that
users can still get a list of recent highlights.
Args:
txn: The transcation
room_id: Room ID to delete from
user_id: user ID to delete for
topological_ordering: The lowe... | def _remove_old_push_actions_before_txn(self, txn, room_id, user_id, topological_ordering, stream_ordering):
| txn.call_after(self.get_unread_event_push_actions_by_room_for_user.invalidate_many, (room_id, user_id))
txn.execute('DELETE FROM event_push_actions WHERE user_id = ? AND room_id = ? AND topological_ordering <= ? AND ((stream_ordering < ? AND hi... |
'Find the stream_ordering of the first event that was received after
a given timestamp. This is relatively slow as there is no index on
received_ts but we can then use this to delete push actions before
this.
received_ts must necessarily be in the same order as stream_ordering
and stream_ordering is indexed, so we manu... | def _find_first_stream_ordering_after_ts_txn(self, txn, ts):
| txn.execute('SELECT MAX(stream_ordering) FROM events')
max_stream_ordering = txn.fetchone()[0]
if (max_stream_ordering is None):
return 0
range_start = 0
range_end = max_stream_ordering
sql = 'SELECT received_ts FROM events WHERE stream_ordering > ? ORDER... |
'Archives older notifications into event_push_summary. Returns whether
the archiving process has caught up or not.'
| def _rotate_notifs_txn(self, txn):
| old_rotate_stream_ordering = self._simple_select_one_onecol_txn(txn, table='event_push_summary_stream_ordering', keyvalues={}, retcol='stream_ordering')
txn.execute('\n SELECT stream_ordering FROM event_push_actions\n ... |
'Fetch non-offline presence from the database so that we can register
the appropriate time outs.'
| def _get_active_presence(self, db_conn):
| sql = 'SELECT user_id, state, last_active_ts, last_federation_update_ts, last_user_sync_ts, status_msg, currently_active FROM presence_stream WHERE state != ?'
sql = self.database_engine.convert_param_style(sql)
txn = db_conn.cursor()
txn.execute(sql, (PresenceStat... |
'Counts the number of users who used this homeserver in the last 24 hours.'
| @defer.inlineCallbacks
def count_daily_users(self):
| def _count_users(txn):
yesterday = ((int(self._clock.time_msec()) - (((1000 * 60) * 60) * 24)),)
sql = '\n SELECT COALESCE(count(*), 0) FROM (\n S... |
'Function to reterive a list of users in users table.
Args:
Returns:
defer.Deferred: resolves to list[dict[str, Any]]'
| def get_users(self):
| return self._simple_select_list(table='users', keyvalues={}, retcols=['name', 'password_hash', 'is_guest', 'admin'], desc='get_users')
|
'Function to reterive a paginated list of users from
users list. This will return a json object, which contains
list of users and the total number of users in users table.
Args:
order (str): column name to order the select by this column
start (int): start number to begin the query from
limit (int): number of rows to r... | def get_users_paginate(self, order, start, limit):
| is_guest = 0
i_start = int(start)
i_limit = int(limit)
return self.get_user_list_paginate(table='users', keyvalues={'is_guest': is_guest}, pagevalues=[order, i_limit, i_start], retcols=['name', 'password_hash', 'is_guest', 'admin'], desc='get_users_paginate')
|
'Function to search users list for one or more users with
the matched term.
Args:
term (str): search term
col (str): column to query term should be matched to
Returns:
defer.Deferred: resolves to list[dict[str, Any]]'
| def search_users(self, term):
| return self._simple_search_list(table='users', term=term, col='name', retcols=['name', 'password_hash', 'is_guest', 'admin'], desc='search_users')
|
'Get all the client account_data for a user.
Args:
user_id(str): The user to get the account_data for.
Returns:
A deferred pair of a dict of global account_data and a dict
mapping from room_id string to per room account_data dicts.'
| @cached()
def get_account_data_for_user(self, user_id):
| def get_account_data_for_user_txn(txn):
rows = self._simple_select_list_txn(txn, 'account_data', {'user_id': user_id}, ['account_data_type', 'content'])
global_account_data = {row['account_data_type']: json.loads(row['content']) for row in rows}
rows = self._simple_select_list_txn(txn, 'room... |
'Returns:
Deferred: A dict'
| @cachedInlineCallbacks(num_args=2)
def get_global_account_data_by_type_for_user(self, data_type, user_id):
| result = (yield self._simple_select_one_onecol(table='account_data', keyvalues={'user_id': user_id, 'account_data_type': data_type}, retcol='content', desc='get_global_account_data_by_type_for_user', allow_none=True))
if result:
defer.returnValue(json.loads(result))
else:
defer.returnValue(N... |
'Get all the client account_data for a user for a room.
Args:
user_id(str): The user to get the account_data for.
room_id(str): The room to get the account_data for.
Returns:
A deferred dict of the room account_data'
| def get_account_data_for_room(self, user_id, room_id):
| def get_account_data_for_room_txn(txn):
rows = self._simple_select_list_txn(txn, 'room_account_data', {'user_id': user_id, 'room_id': room_id}, ['account_data_type', 'content'])
return {row['account_data_type']: json.loads(row['content']) for row in rows}
return self.runInteraction('get_account_... |
'Get all the client account_data that has changed on the server
Args:
last_global_id(int): The position to fetch from for top level data
last_room_id(int): The position to fetch from for per room data
current_id(int): The position to fetch up to.
Returns:
A deferred pair of lists of tuples of stream_id int, user_id str... | def get_all_updated_account_data(self, last_global_id, last_room_id, current_id, limit):
| if ((last_room_id == current_id) and (last_global_id == current_id)):
return defer.succeed(([], []))
def get_updated_account_data_txn(txn):
sql = 'SELECT stream_id, user_id, account_data_type, content FROM account_data WHERE ? < stream_id AND stream_id <= ... |
'Get all the client account_data for a that\'s changed for a user
Args:
user_id(str): The user to get the account_data for.
stream_id(int): The point in the stream since which to get updates
Returns:
A deferred pair of a dict of global account_data and a dict
mapping from room_id string to per room account_data dicts.'... | def get_updated_account_data_for_user(self, user_id, stream_id):
| def get_updated_account_data_for_user_txn(txn):
sql = 'SELECT account_data_type, content FROM account_data WHERE user_id = ? AND stream_id > ?'
txn.execute(sql, (user_id, stream_id))
global_account_data = {row[0]: json.loads(row[1]) for row in txn}
... |
'Add some account_data to a room for a user.
Args:
user_id(str): The user to add a tag for.
room_id(str): The room to add a tag for.
account_data_type(str): The type of account_data to add.
content(dict): A json object to associate with the tag.
Returns:
A deferred that completes once the account_data has been added.'
| @defer.inlineCallbacks
def add_account_data_to_room(self, user_id, room_id, account_data_type, content):
| content_json = json.dumps(content)
def add_account_data_txn(txn, next_id):
self._simple_upsert_txn(txn, table='room_account_data', keyvalues={'user_id': user_id, 'room_id': room_id, 'account_data_type': account_data_type}, values={'stream_id': next_id, 'content': content_json})
txn.call_after(se... |
'Add some account_data to a room for a user.
Args:
user_id(str): The user to add a tag for.
account_data_type(str): The type of account_data to add.
content(dict): A json object to associate with the tag.
Returns:
A deferred that completes once the account_data has been added.'
| @defer.inlineCallbacks
def add_account_data_for_user(self, user_id, account_data_type, content):
| content_json = json.dumps(content)
def add_account_data_txn(txn, next_id):
self._simple_upsert_txn(txn, table='account_data', keyvalues={'user_id': user_id, 'account_data_type': account_data_type}, values={'stream_id': next_id, 'content': content_json})
txn.call_after(self._account_data_stream_c... |
'Update the max stream_id
Args:
txn: The database cursor
next_id(int): The the revision to advance to.'
| def _update_max_stream_id(self, txn, next_id):
| update_max_id_sql = 'UPDATE account_data_max_stream_id SET stream_id = ? WHERE stream_id < ?'
txn.execute(update_max_id_sql, (next_id, next_id))
|
'Get all the hashes for a given PDU.
Args:
txn (cursor):
event_id (str): Id for the Event.
Returns:
A dict of algorithm -> hash.'
| def _get_event_reference_hashes_txn(self, txn, event_id):
| query = 'SELECT algorithm, hash FROM event_reference_hashes WHERE event_id = ?'
txn.execute(query, (event_id,))
return {k: v for (k, v) in txn}
|
'Store a hash for a PDU
Args:
txn (cursor):
events (list): list of Events.'
| def _store_event_reference_hashes_txn(self, txn, events):
| vals = []
for event in events:
(ref_alg, ref_hash_bytes) = compute_event_reference_hash(event)
vals.append({'event_id': event.event_id, 'algorithm': ref_alg, 'hash': buffer(ref_hash_bytes)})
self._simple_insert_many_txn(txn, table='event_reference_hashes', values=vals)
|
'Get the metadata for a local piece of media
Returns:
None if the media_id doesn\'t exist.'
| def get_local_media(self, media_id):
| return self._simple_select_one('local_media_repository', {'media_id': media_id}, ('media_type', 'media_length', 'upload_name', 'created_ts', 'quarantined_by', 'url_cache'), allow_none=True, desc='get_local_media')
|
'Get the media_id and ts for a cached URL as of the given timestamp
Returns:
None if the URL isn\'t cached.'
| def get_url_cache(self, url, ts):
| def get_url_cache_txn(txn):
sql = 'SELECT response_code, etag, expires, og, media_id, download_ts FROM local_media_repository_url_cache WHERE url = ? AND download_ts <= ? ORDER BY download_ts DESC LIMIT 1'
txn.execute(sql, (url, ts))
... |
'Used to send messages from this server.
Args:
sender_user_id(str): The ID of the user sending these messages.
local_messages_by_user_and_device(dict):
Dictionary of user_id to device_id to message.
remote_messages_by_destination(dict):
Dictionary of destination server_name to the EDU JSON to send.
Returns:
A deferred ... | @defer.inlineCallbacks
def add_messages_to_device_inbox(self, local_messages_by_user_then_device, remote_messages_by_destination):
| def add_messages_txn(txn, now_ms, stream_id):
self._add_messages_to_local_device_inbox_txn(txn, stream_id, local_messages_by_user_then_device)
sql = 'INSERT INTO device_federation_outbox (destination, stream_id, queued_ts, messages_json) VALUES (?,?,?,?)'
rows = []
... |
'Args:
user_id(str): The recipient user_id.
device_id(str): The recipient device_id.
current_stream_id(int): The current position of the to device
message stream.
Returns:
Deferred ([dict], int): List of messages for the device and where
in the stream the messages got to.'
| def get_new_messages_for_device(self, user_id, device_id, last_stream_id, current_stream_id, limit=100):
| has_changed = self._device_inbox_stream_cache.has_entity_changed(user_id, last_stream_id)
if (not has_changed):
return defer.succeed(([], current_stream_id))
def get_new_messages_for_device_txn(txn):
sql = 'SELECT stream_id, message_json FROM device_inbox WHERE user_id =... |
'Args:
user_id(str): The recipient user_id.
device_id(str): The recipient device_id.
up_to_stream_id(int): Where to delete messages up to.
Returns:
A deferred that resolves to the number of messages deleted.'
| @defer.inlineCallbacks
def delete_messages_for_device(self, user_id, device_id, up_to_stream_id):
| last_deleted_stream_id = self._last_device_delete_cache.get((user_id, device_id), None)
if last_deleted_stream_id:
has_changed = self._device_inbox_stream_cache.has_entity_changed(user_id, last_deleted_stream_id)
if (not has_changed):
defer.returnValue(0)
def delete_messages_for_... |
'Args:
last_pos(int):
current_pos(int):
limit(int):
Returns:
A deferred list of rows from the device inbox'
| def get_all_new_device_messages(self, last_pos, current_pos, limit):
| if (last_pos == current_pos):
return defer.succeed([])
def get_all_new_device_messages_txn(txn):
upper_pos = min(current_pos, (last_pos + limit))
sql = 'SELECT max(stream_id), user_id FROM device_inbox WHERE ? < stream_id AND stream_id <= ? GROUP ... |
'Args:
destination(str): The name of the remote server.
last_stream_id(int|long): The last position of the device message stream
that the server sent up to.
current_stream_id(int|long): The current position of the device
message stream.
Returns:
Deferred ([dict], int|long): List of messages for the device and where
in ... | def get_new_device_msgs_for_remote(self, destination, last_stream_id, current_stream_id, limit=100):
| has_changed = self._device_federation_outbox_stream_cache.has_entity_changed(destination, last_stream_id)
if ((not has_changed) or (last_stream_id == current_stream_id)):
return defer.succeed(([], current_stream_id))
def get_new_messages_for_remote_destination_txn(txn):
sql = 'SELECT stre... |
'Used to delete messages when the remote destination acknowledges
their receipt.
Args:
destination(str): The destination server_name
up_to_stream_id(int): Where to delete messages up to.
Returns:
A deferred that resolves when the messages have been deleted.'
| def delete_device_msgs_for_remote(self, destination, up_to_stream_id):
| def delete_messages_for_remote_destination_txn(txn):
sql = 'DELETE FROM device_federation_outbox WHERE destination = ? AND stream_id <= ?'
txn.execute(sql, (destination, up_to_stream_id))
return self.runInteraction('delete_device_msgs_for_remote', delete_messages_fo... |
'Retrieve the TLS X.509 certificate for the given server
Args:
server_name (bytes): The name of the server.
Returns:
(OpenSSL.crypto.X509): The tls certificate.'
| @defer.inlineCallbacks
def get_server_certificate(self, server_name):
| (tls_certificate_bytes,) = (yield self._simple_select_one(table='server_tls_certificates', keyvalues={'server_name': server_name}, retcols=('tls_certificate',), desc='get_server_certificate'))
tls_certificate = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, tls_certificate_bytes)
defer.return... |
'Stores the TLS X.509 certificate for the given server
Args:
server_name (str): The name of the server.
from_server (str): Where the certificate was looked up
time_now_ms (int): The time now in milliseconds
tls_certificate (OpenSSL.crypto.X509): The X.509 certificate.'
| def store_server_certificate(self, server_name, from_server, time_now_ms, tls_certificate):
| tls_certificate_bytes = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_ASN1, tls_certificate)
fingerprint = hashlib.sha256(tls_certificate_bytes).hexdigest()
return self._simple_upsert(table='server_tls_certificates', keyvalues={'server_name': server_name, 'fingerprint': fingerprint}, values={'from... |
'Retrieve the NACL verification key for a given server for the given
key_ids
Args:
server_name (str): The name of the server.
key_ids (iterable[str]): key_ids to try and look up.
Returns:
Deferred: resolves to dict[str, VerifyKey]: map from
key_id to verification key.'
| @defer.inlineCallbacks
def get_server_verify_keys(self, server_name, key_ids):
| keys = {}
for key_id in key_ids:
key = (yield self._get_server_verify_key(server_name, key_id))
if key:
keys[key_id] = key
defer.returnValue(keys)
|
'Stores a NACL verification key for the given server.
Args:
server_name (str): The name of the server.
key_id (str): The version of the key for the server.
from_server (str): Where the verification key was looked up
ts_now_ms (int): The time now in milliseconds
verification_key (VerifyKey): The NACL verify key.'
| @defer.inlineCallbacks
def store_server_verify_key(self, server_name, from_server, time_now_ms, verify_key):
| (yield self._simple_upsert(table='server_signature_keys', keyvalues={'server_name': server_name, 'key_id': ('%s:%s' % (verify_key.alg, verify_key.version))}, values={'from_server': from_server, 'ts_added_ms': time_now_ms, 'verify_key': buffer(verify_key.encode())}, desc='store_server_verify_key'))
|
'Stores the JSON bytes for a set of keys from a server
The JSON should be signed by the originating server, the intermediate
server, and by this server. Updates the value for the
(server_name, key_id, from_server) triplet if one already existed.
Args:
server_name (str): The name of the server.
key_id (str): The identif... | def store_server_keys_json(self, server_name, key_id, from_server, ts_now_ms, ts_expires_ms, key_json_bytes):
| return self._simple_upsert(table='server_keys_json', keyvalues={'server_name': server_name, 'key_id': key_id, 'from_server': from_server}, values={'server_name': server_name, 'key_id': key_id, 'from_server': from_server, 'ts_added_ms': ts_now_ms, 'ts_valid_until_ms': ts_expires_ms, 'key_json': buffer(key_json_bytes... |
'Retrive the key json for a list of server_keys and key ids.
If no keys are found for a given server, key_id and source then
that server, key_id, and source triplet entry will be an empty list.
The JSON is returned as a byte array so that it can be efficiently
used in an HTTP response.
Args:
server_keys (list): List of... | def get_server_keys_json(self, server_keys):
| def _get_server_keys_json_txn(txn):
results = {}
for (server_name, key_id, from_server) in server_keys:
keyvalues = {'server_name': server_name}
if (key_id is not None):
keyvalues['key_id'] = key_id
if (from_server is not None):
key... |
'Get\'s the room_id and server list for a given room_alias
Args:
room_alias (RoomAlias)
Returns:
Deferred: results in namedtuple with keys "room_id" and
"servers" or None if no association can be found'
| @defer.inlineCallbacks
def get_association_from_room_alias(self, room_alias):
| room_id = (yield self._simple_select_one_onecol('room_aliases', {'room_alias': room_alias.to_string()}, 'room_id', allow_none=True, desc='get_association_from_room_alias'))
if (not room_id):
defer.returnValue(None)
return
servers = (yield self._simple_select_onecol('room_alias_servers', {'ro... |
'Creates an associatin between a room alias and room_id/servers
Args:
room_alias (RoomAlias)
room_id (str)
servers (list)
creator (str): Optional user_id of creator.
Returns:
Deferred'
| @defer.inlineCallbacks
def create_room_alias_association(self, room_alias, room_id, servers, creator=None):
| def alias_txn(txn):
self._simple_insert_txn(txn, 'room_aliases', {'room_alias': room_alias.to_string(), 'room_id': room_id, 'creator': creator})
self._simple_insert_many_txn(txn, table='room_alias_servers', values=[{'room_alias': room_alias.to_string(), 'server': server} for server in servers])
... |
'Get all the pushers that have changed between the given tokens.
Returns:
Deferred(list(tuple)): each tuple consists of:
stream_id (str)
user_id (str)
app_id (str)
pushkey (str)
was_deleted (bool): whether the pusher was added/updated (False)
or deleted (True)'
| def get_all_updated_pushers_rows(self, last_id, current_id, limit):
| if (last_id == current_id):
return defer.succeed([])
def get_all_updated_pushers_rows_txn(txn):
sql = 'SELECT id, user_name, app_id, pushkey FROM pushers WHERE ? < id AND id <= ? ORDER BY id ASC LIMIT ?'
txn.execute(sql, (last_i... |
'Ensure the given device is known; add it to the store if not
Args:
user_id (str): id of user associated with the device
device_id (str): id of device
initial_device_display_name (str): initial displayname of the
device. Ignored if device exists.
Returns:
defer.Deferred: boolean whether the device was inserted or an
ex... | @defer.inlineCallbacks
def store_device(self, user_id, device_id, initial_device_display_name):
| key = (user_id, device_id)
if self.device_id_exists_cache.get(key, None):
defer.returnValue(False)
try:
inserted = (yield self._simple_insert('devices', values={'user_id': user_id, 'device_id': device_id, 'display_name': initial_device_display_name}, desc='store_device', or_ignore=True))
... |
'Retrieve a device.
Args:
user_id (str): The ID of the user which owns the device
device_id (str): The ID of the device to retrieve
Returns:
defer.Deferred for a dict containing the device information
Raises:
StoreError: if the device is not found'
| def get_device(self, user_id, device_id):
| return self._simple_select_one(table='devices', keyvalues={'user_id': user_id, 'device_id': device_id}, retcols=('user_id', 'device_id', 'display_name'), desc='get_device')
|
'Delete a device.
Args:
user_id (str): The ID of the user which owns the device
device_id (str): The ID of the device to delete
Returns:
defer.Deferred'
| @defer.inlineCallbacks
def delete_device(self, user_id, device_id):
| (yield self._simple_delete_one(table='devices', keyvalues={'user_id': user_id, 'device_id': device_id}, desc='delete_device'))
self.device_id_exists_cache.invalidate((user_id, device_id))
|
'Deletes several devices.
Args:
user_id (str): The ID of the user which owns the devices
device_ids (list): The IDs of the devices to delete
Returns:
defer.Deferred'
| @defer.inlineCallbacks
def delete_devices(self, user_id, device_ids):
| (yield self._simple_delete_many(table='devices', column='device_id', iterable=device_ids, keyvalues={'user_id': user_id}, desc='delete_devices'))
for device_id in device_ids:
self.device_id_exists_cache.invalidate((user_id, device_id))
|
'Update a device.
Args:
user_id (str): The ID of the user which owns the device
device_id (str): The ID of the device to update
new_display_name (str|None): new displayname for device; None
to leave unchanged
Raises:
StoreError: if the device is not found
Returns:
defer.Deferred'
| def update_device(self, user_id, device_id, new_display_name=None):
| updates = {}
if (new_display_name is not None):
updates['display_name'] = new_display_name
if (not updates):
return defer.succeed(None)
return self._simple_update_one(table='devices', keyvalues={'user_id': user_id, 'device_id': device_id}, updatevalues=updates, desc='update_device')
|
'Retrieve all of a user\'s registered devices.
Args:
user_id (str):
Returns:
defer.Deferred: resolves to a dict from device_id to a dict
containing "device_id", "user_id" and "display_name" for each
device.'
| @defer.inlineCallbacks
def get_devices_by_user(self, user_id):
| devices = (yield self._simple_select_list(table='devices', keyvalues={'user_id': user_id}, retcols=('user_id', 'device_id', 'display_name'), desc='get_devices_by_user'))
defer.returnValue({d['device_id']: d for d in devices})
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.