MCPcopy
hub / github.com/liangliangyy/DjangoBlog / model_post_save_callback

Function model_post_save_callback

djangoblog/blog_signals.py:68–169  ·  view source on GitHub ↗
(
        sender,
        instance,
        created,
        raw,
        using,
        update_fields,
        **kwargs)

Source from the content-addressed store, hash-verified

66
67@receiver(post_save)
68def model_post_save_callback(
69 sender,
70 instance,
71 created,
72 raw,
73 using,
74 update_fields,
75 **kwargs):
76 if isinstance(instance, LogEntry):
77 return
78
79 # 检查是否只更新了浏览量
80 is_update_views = update_fields == {'views'}
81 if is_update_views:
82 return # 浏览量更新不需要清理缓存
83
84 # 搜索引擎通知
85 if 'get_full_url' in dir(instance):
86 if not settings.TESTING:
87 try:
88 notify_url = instance.get_full_url()
89 SpiderNotify.baidu_notify([notify_url])
90 except Exception as ex:
91 logger.error("notify sipder", ex)
92
93 # 评论相关的缓存清理
94 if isinstance(instance, Comment):
95 if instance.is_enable:
96 path = instance.article.get_absolute_url()
97 site = get_current_site().domain
98 if site.find(':') > 0:
99 site = site[0:site.find(':')]
100
101 expire_view_cache(
102 path,
103 servername=site,
104 serverport=80,
105 key_prefix='blogdetail')
106
107 # 清理评论相关缓存
108 comment_cache_key = 'article_comments_{id}'.format(
109 id=instance.article.id)
110 cache.delete(comment_cache_key)
111 delete_view_cache('article_comments', [str(instance.article.pk)])
112 delete_sidebar_cache()
113 cache.delete('seo_processor')
114
115 _thread.start_new_thread(send_comment_email, (instance,))
116
117 # 文章相关的精细化缓存清理
118 elif 'get_full_url' in dir(instance):
119 from blog.models import Article, Category, Tag
120
121 if isinstance(instance, Article):
122 # 清理文章列表首页缓存
123 cache.delete('index_1')
124
125 # 清理文章详情缓存

Callers

nothing calls this directly

Calls 8

get_current_siteFunction · 0.90
expire_view_cacheFunction · 0.90
delete_view_cacheFunction · 0.90
delete_sidebar_cacheFunction · 0.90
baidu_notifyMethod · 0.80
deleteMethod · 0.80
get_full_urlMethod · 0.45
get_absolute_urlMethod · 0.45

Tested by

no test coverage detected