Beispiel #1
0
 def new(
     cls,
     article_id: int,
     title: str,
     language_id: int,
     editor_id: int,
     contents: str,
 ) -> Optional['WikiRevision']:
     WikiArticle.is_valid(article_id, error=True)
     WikiLanguage.is_valid(language_id, error=True)
     try:
         old_latest_id = (
             cls.latest_revision(article_id).revision_id + 1
         )  # type: ignore
     except WikiNoRevisions:
         old_latest_id = 1
     cache.delete_many(
         cls.__cache_key_of_article__.format(article_id=article_id),
         cls.__cache_key_latest_id_of_article__.format(
             article_id=article_id
         ),
     )
     return super()._new(
         revision_id=old_latest_id,
         article_id=article_id,
         title=title,
         language_id=language_id,
         editor_id=editor_id,
         contents=contents,
     )
Beispiel #2
0
 def clear_cache_keys(cls, user_id: int, type=None) -> None:
     types = ([NotificationType.from_type(type, error=True)]
              if type else NotificationType.get_all())
     cache.delete_many(*chain(*chain([(
         cls.__cache_key_notification_count__.format(user_id=user_id,
                                                     type=t.id),
         cls.__cache_key_of_user__.format(user_id=user_id, type=t.id),
     ) for t in types])))
Beispiel #3
0
 def update_last_response_time(cls, conv_id: int, sender_id: int) -> None:
     db.session.query(cls).filter(
         and_(cls.conv_id == conv_id, cls.user_id != sender_id)).update(
             {'last_response_time': datetime.utcnow()})
     db.session.commit()
     cache.delete_many(*(cls.create_cache_key({
         'conv_id': conv_id,
         'user_id': uid
     }) for uid in cls.get_user_ids_in_conversation(conv_id)
                         if uid != sender_id))
Beispiel #4
0
def test_cache_delete_many(app, client):
    cache.set('key_1', 1)
    cache.set('key_2', 2)
    assert cache.delete_many('key_1', 'key_2', 'key_3')
    with app.test_request_context('/test'):
        assert 'key_1' in flask.g.cache_keys['delete_many']
        assert 'key_2' in flask.g.cache_keys['delete_many']
        assert 'key_3' in flask.g.cache_keys['delete_many']
Beispiel #5
0
    def clear_cache_keys(
        cls, user_ids: List[int] = None, thread_id: int = None
    ) -> None:
        """
        Clear the cache keys associated with specific users and/or threads. Clearing a thread
        cache key also clears the cache keys for all of its users

        :param user_ids: The IDs of the users whose cache keys should be cleared
        :param thread_id: The ID of the thread for which the cache key should be cleared
        """
        user_ids = (
            user_ids or []
        )  # Don't put a mutable object as default kwarg!
        if thread_id:
            cache.delete(cls.__cache_key_users__.format(thread_id=thread_id))
            user_ids += cls.user_ids_from_thread(thread_id)
        if user_ids:
            cache.delete_many(
                *(
                    cls.__cache_key_of_user__.format(user_id=uid)
                    for uid in user_ids
                )
            )
Beispiel #6
0
 def clear_cache_keys(cls, user_id: int):
     cache.delete_many(
         *(cls.__cache_key_of_user__.format(user_id=user_id, filter=f)
           for f in ['inbox', 'sentbox', 'deleted']))