diff --git a/oml/queryparser.py b/oml/queryparser.py index 2810729..939611b 100644 --- a/oml/queryparser.py +++ b/oml/queryparser.py @@ -129,7 +129,7 @@ class Parser(object): nickname, name = v.split(':', 1) if nickname: try: - u = self._user.query.filter_by(nickname=nickname).one() + u = self._user.query.filter_by(nickname=nickname, peered=True).one() except sqlalchemy.orm.exc.NoResultFound: ids = [] return self.in_ids(ids, exclude) diff --git a/oml/settings.py b/oml/settings.py index 4ef0843..bdc6c31 100644 --- a/oml/settings.py +++ b/oml/settings.py @@ -95,4 +95,4 @@ FULLTEXT_SUPPORT = fulltext.platform_supported() if not FULLTEXT_SUPPORT: config['itemKeys'] = [k for k in config['itemKeys'] if k['id'] != 'fulltext'] -DB_VERSION = 15 +DB_VERSION = 16 diff --git a/oml/setup.py b/oml/setup.py index b243a00..69024d0 100644 --- a/oml/setup.py +++ b/oml/setup.py @@ -43,11 +43,11 @@ CREATE TABLE user ( peered BOOLEAN, online BOOLEAN, PRIMARY KEY (id), - UNIQUE (nickname), CHECK (queued IN (0, 1)), CHECK (peered IN (0, 1)), CHECK (online IN (0, 1)) ); +CREATE INDEX ix_user_nichname ON user (nichname); CREATE TABLE metadata ( created DATETIME, modified DATETIME, diff --git a/oml/update.py b/oml/update.py index 07cddb4..4177800 100644 --- a/oml/update.py +++ b/oml/update.py @@ -373,6 +373,8 @@ class Update(Thread): db_version = migrate_13() if db_version < 15: db_version = migrate_15() + if db_version < 16: + db_version = migrate_16() settings.server['db_version'] = db_version def run(self): @@ -437,7 +439,7 @@ def migrate_5(): 'DROP INDEX IF EXISTS user_metadata_index', 'CREATE UNIQUE INDEX user_metadata_index ON user_metadata(item_id, user_id)', 'UPDATE sort SET sharemetadata = 0', - ]), + ]) with db.session() as session: import user.models for m in user.models.Metadata.query: @@ -631,3 +633,28 @@ def migrate_15(): del u.info['local'] u.save() return 15 + +def migrate_16(): + db.run_sql([ + '''CREATE TABLE user2 ( + created DATETIME, + modified DATETIME, + id VARCHAR(43) NOT NULL, + info BLOB, + nickname VARCHAR(256), + pending VARCHAR(64), + queued BOOLEAN, + peered BOOLEAN, + online BOOLEAN, + PRIMARY KEY (id), + CHECK (queued IN (0, 1)), + CHECK (peered IN (0, 1)), + CHECK (online IN (0, 1)) + )''', + '''INSERT INTO user2 (created, modified, id, info, nickname, pending, queued, peered, online) + SELECT created, modified, id, info, nickname, pending, queued, peered, online FROM user''', + 'DROP TABLE user', + 'ALTER TABLE user2 RENAME TO user', + 'CREATE INDEX IF NOT EXISTS ix_user_nickname ON user (nickname)' + ]) + return 16 diff --git a/oml/user/models.py b/oml/user/models.py index 3d7284a..8e7164d 100644 --- a/oml/user/models.py +++ b/oml/user/models.py @@ -30,7 +30,7 @@ class User(db.Model): id = sa.Column(sa.String(43), primary_key=True) info = sa.Column(MutableDict.as_mutable(sa.PickleType(pickler=json_pickler))) - nickname = sa.Column(sa.String(256), unique=True) + nickname = sa.Column(sa.String(256), index=True) pending = sa.Column(sa.String(64)) # sent|received queued = sa.Column(sa.Boolean()) diff --git a/oml/websocket.py b/oml/websocket.py index 12795ce..9178bb8 100644 --- a/oml/websocket.py +++ b/oml/websocket.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - -from tornado.websocket import WebSocketHandler +from tornado.websocket import WebSocketHandler, WebSocketClosedError from tornado.ioloop import IOLoop +from tornado.iostream import StreamClosedError import json from oxtornado import json_dumps @@ -72,9 +72,9 @@ class Handler(WebSocketHandler): try: task = self.write_message(message) await task - except tornado.iostream.StreamClosedError as e: + except StreamClosedError as e: self.on_close() - except tornado.websocket.WebSocketClosedError as e: + except WebSocketClosedError as e: self.on_close()