mirror of
				https://github.com/MCV-Software/TWBlue.git
				synced 2025-10-31 20:22:01 +00:00 
			
		
		
		
	Faster implementation of dm loading due to a call to lookup_users instead to get_user
This commit is contained in:
		| @@ -13,6 +13,7 @@ | |||||||
| * Fixed the way we use to count characters in Twitter. The new methods in TWBlue take into account special characters and URLS as documented in Twitter. ([#199,](https://github.com/manuelcortez/TWBlue/issues/199) [#315](https://github.com/manuelcortez/TWBlue/issues/315)) | * Fixed the way we use to count characters in Twitter. The new methods in TWBlue take into account special characters and URLS as documented in Twitter. ([#199,](https://github.com/manuelcortez/TWBlue/issues/199) [#315](https://github.com/manuelcortez/TWBlue/issues/315)) | ||||||
| * Proxy support now works as expected. | * Proxy support now works as expected. | ||||||
| * Changed translation service from yandex.translate to Google Translator. ([#355,](https://github.com/manuelcortez/TWBlue/issues/355)) | * Changed translation service from yandex.translate to Google Translator. ([#355,](https://github.com/manuelcortez/TWBlue/issues/355)) | ||||||
|  | * Improved method to load direct messages in the buffers. Now it should be faster due to less calls to Twitter API performed from the client. | ||||||
| * And more. ([#352,](https://github.com/manuelcortez/TWBlue/issues/352)) | * And more. ([#352,](https://github.com/manuelcortez/TWBlue/issues/352)) | ||||||
|  |  | ||||||
| ## Changes in version 0.95 | ## Changes in version 0.95 | ||||||
|   | |||||||
| @@ -181,11 +181,14 @@ class baseBufferController(baseBuffers.buffer): | |||||||
|      val = results |      val = results | ||||||
|      val.reverse() |      val.reverse() | ||||||
|      log.debug("Retrieved %d items from the cursored search on function %s." %(len(val), self.function)) |      log.debug("Retrieved %d items from the cursored search on function %s." %(len(val), self.function)) | ||||||
|  |      user_ids = [item.message_create["sender_id"] for item in val] | ||||||
|  |      self.session.save_users(user_ids) | ||||||
|     except TweepError as e: |     except TweepError as e: | ||||||
|      log.error("Error %s: %s" % (e.api_code, e.reason)) |      log.error("Error %s: %s" % (e.api_code, e.reason)) | ||||||
|      return |      return | ||||||
|    number_of_items = self.session.order_buffer(self.name, val) |    number_of_items = self.session.order_buffer(self.name, val) | ||||||
|    log.debug("Number of items retrieved: %d" % (number_of_items,)) |    log.debug("Number of items retrieved: %d" % (number_of_items,)) | ||||||
|  |  | ||||||
|    self.put_items_on_list(number_of_items) |    self.put_items_on_list(number_of_items) | ||||||
|    if hasattr(self, "finished_timeline") and self.finished_timeline == False: |    if hasattr(self, "finished_timeline") and self.finished_timeline == False: | ||||||
|     if "-timeline" in self.name: |     if "-timeline" in self.name: | ||||||
| @@ -664,9 +667,10 @@ class directMessagesController(baseBufferController): | |||||||
|      self.session.db[self.name].append(i) |      self.session.db[self.name].append(i) | ||||||
|      received.insert(0, i) |      received.insert(0, i) | ||||||
|    total = total+1 |    total = total+1 | ||||||
|  |   user_ids = [item.message_create["sender_id"] for item in items] | ||||||
|  |   self.session.save_users(user_ids) | ||||||
|   pub.sendMessage("more-sent-dms", data=sent, account=self.session.db["user_name"]) |   pub.sendMessage("more-sent-dms", data=sent, account=self.session.db["user_name"]) | ||||||
|   selected = self.buffer.list.get_selected() |   selected = self.buffer.list.get_selected() | ||||||
|  |  | ||||||
|   if self.session.settings["general"]["reverse_timelines"] == True: |   if self.session.settings["general"]["reverse_timelines"] == True: | ||||||
|    for i in received: |    for i in received: | ||||||
|     if int(i.message_create["sender_id"]) == self.session.db["user_id"]: |     if int(i.message_create["sender_id"]) == self.session.db["user_id"]: | ||||||
|   | |||||||
| @@ -431,3 +431,15 @@ class Session(base.baseSession): | |||||||
|    user = utils.if_user_exists(self.twitter, screen_name) |    user = utils.if_user_exists(self.twitter, screen_name) | ||||||
|    self.db["users"][user.id_str] = user |    self.db["users"][user.id_str] = user | ||||||
|    return user.id_str |    return user.id_str | ||||||
|  |  | ||||||
|  |  def save_users(self, user_ids): | ||||||
|  |   """ Adds all new users to the users database. """ | ||||||
|  |   log.debug("Received %d user IDS to be added in the database." % (len(user_ids))) | ||||||
|  |   users_to_retrieve = [user_id for user_id in user_ids if user_id not in self.db["users"]] | ||||||
|  |   # Remove duplicates | ||||||
|  |   users_to_retrieve = list(dict.fromkeys(users_to_retrieve)) | ||||||
|  |   log.debug("TWBlue will get %d new users from Twitter." % (len(users_to_retrieve))) | ||||||
|  |   users = self.twitter.lookup_users(user_ids=users_to_retrieve, tweet_mode="extended") | ||||||
|  |   for user in users: | ||||||
|  |    self.db["users"][user.id_str] = user | ||||||
|  |   log.debug("Added %d new users" % (len(users))) | ||||||
		Reference in New Issue
	
	Block a user