# HG changeset patch # User Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com> # Date 1311780196 -7200 # Node ID 6334869ab06dd9c2531e7ad7d36b48a9ce8e114d # Parent b31aef9365a8c52ced8b7cdbce1852f2490c2571 optimise database and correct bug on user mention diff -r b31aef9365a8 -r 6334869ab06d script/lib/iri_tweet/models.py --- a/script/lib/iri_tweet/models.py Wed Jul 27 12:29:02 2011 +0200 +++ b/script/lib/iri_tweet/models.py Wed Jul 27 17:23:16 2011 +0200 @@ -124,7 +124,7 @@ profile_text_color= Column(String) profile_use_background_image= Column(Boolean) protected= Column(Boolean) - screen_name= Column(String) + screen_name= Column(String, index=True, unique=True) show_all_inline_media= Column(Boolean) statuses_count = Column(Integer) time_zone= Column(String) @@ -143,7 +143,7 @@ class Hashtag(Base): __tablename__ = "tweet_hashtag" id = Column(Integer, primary_key=True) - text = Column(String, unique = True) + text = Column(String, unique = True, index = True) def __init__(self, **kwargs): for key, value in kwargs.items(): if hasattr(self,key): @@ -204,7 +204,7 @@ def setup_database(*args, **kwargs): - create_all = True + create_all = True if "create_all" in kwargs: create_all = kwargs["create_all"] del(kwargs["create_all"]) diff -r b31aef9365a8 -r 6334869ab06d script/lib/iri_tweet/utils.py --- a/script/lib/iri_tweet/utils.py Wed Jul 27 12:29:02 2011 +0200 +++ b/script/lib/iri_tweet/utils.py Wed Jul 27 17:23:16 2011 +0200 @@ -116,7 +116,7 @@ if user_id: user = self.session.query(User).filter(User.id == user_id).first() else: - user = self.session.query(User).filter(User.screen_name == user_name).first() + user = self.session.query(User).filter(User.screen_name.ilike(user_name)).first() if user is not None: return user @@ -134,11 +134,17 @@ except Exception as e: logging.info("get_user : TWITTER ERROR : " + repr(e)) #@UndefinedVariable logging.info("get_user : TWITTER ERROR : " + str(e)) #@UndefinedVariable + return None user_dict = adapt_fields(user_dict, fields_adapter["stream"]["user"]) if "id" not in user_dict: return None + user = self.session.query(User).filter(User.id == user_dict["id"]).first() + + if user is not None: + return user + user = User(**user_dict) self.session.add(user) @@ -162,8 +168,8 @@ text = ind.get("text", ind.get("hashtag", None)) if text is None: return None - hashtag = self.session.query(Hashtag).filter(Hashtag.text == text).first() - if not hashtag: + hashtag = self.session.query(Hashtag).filter(Hashtag.text.ilike(text)).first() + if hashtag is None: ind["text"] = text hashtag = Hashtag(**ind) self.session.add(hashtag)