def get_active_posters_rankig(): cache_key = "misago_active_posters_ranking" ranking = cache.get(cache_key, "nada") if ranking == "nada": ranking = get_real_active_posts_ranking() cache.set(cache_key, ranking, 18 * 3600) return ranking
def active(request, queryset): cache_key = 'misago_active_posters_ranking' ranking = cache.get(cache_key, False) if ranking is False: ranking = real_active() cache.set(cache_key, ranking, 18 * 3600) return ranking
def active(request, queryset): cache_key = 'misago_active_posters_ranking' ranking = cache.get(cache_key, False) if ranking is False: ranking = real_active() cache.set(cache_key, ranking, 18*3600) return ranking
def get_active_posters_rankig(): cache_key = 'misago_active_posters_ranking' ranking = cache.get(cache_key, 'nada') if ranking == 'nada': ranking = get_real_active_posts_ranking() cache.set(cache_key, ranking, 18*3600) return ranking
def get_active_posters_rankig(): cache_key = 'misago_active_posters_ranking' ranking = cache.get(cache_key, 'nada') if ranking == 'nada': ranking = get_real_active_posts_ranking() cache.set(cache_key, ranking, 18 * 3600) return ranking
def read_cache(self): from misago.core.cache import cache as default_cache data = default_cache.get(CACHE_KEY, 'nada') if data == 'nada': data = self.read_db() default_cache.set(CACHE_KEY, data) return data
def _read_cache(self): from misago.core.cache import cache data = cache.get(CACHE_KEY, 'nada') if data == 'nada': data = self._read_db() cache.set(CACHE_KEY, data) return data
def _read_cache(self): from misago.core.cache import cache data = cache.get(CACHE_KEY, 'nada') if data == 'nada': data = self._read_db() cache.set(CACHE_KEY, data) return data
def get_special(self, special_role): cache_name = '%s_%s' % (CACHE_NAME, special_role) special_category = cache.get(cache_name, 'nada') if special_category == 'nada': special_category = self.get(special_role=special_role) cache.set(cache_name, special_category) return special_category
def get_special(self, special_role): cache_name = '%s_%s' % (CACHE_NAME, special_role) special_category = cache.get(cache_name, 'nada') if special_category == 'nada': special_category = self.get(special_role=special_role) cache.set(cache_name, special_category) return special_category
def read_cache(self): from misago.core.cache import cache as default_cache data = default_cache.get(CACHE_KEY, 'nada') if data == 'nada': data = self.read_db() default_cache.set(CACHE_KEY, data) return data
def get_special(self, special_role): cache_name = "%s_%s" % (CACHE_NAME, special_role) special_forum = cache.get(cache_name, "nada") if special_forum == "nada": special_forum = self.get(special_role=special_role) cache.set(cache_name, special_forum) return special_forum
def online(request, queryset): allow_see_users_online_list(request.user) cache_key = 'users_online_cache_%s' % request.user.acl_key online_list = cache.get(cache_key, False) if online_list is False: online_list = real_online(request) cache.set(cache_key, online_list, settings.MISAGO_ONLINE_LIST_CACHE) return online_list
def online(request, queryset): allow_see_users_online_list(request.user) cache_key = 'users_online_cache_%s' % request.user.acl_key online_list = cache.get(cache_key, False) if online_list is False: online_list = real_online(request) cache.set(cache_key, online_list, settings.MISAGO_ONLINE_LIST_CACHE) return online_list
def get_cached_labels(self): labels = cache.get(CACHE_NAME, 'nada') if labels == 'nada': labels = [] labels_qs = self.all().prefetch_related('forums') for label in labels_qs.order_by('name'): label.forums_ids = [f.pk for f in label.forums.all()] labels.append(label) cache.set(CACHE_NAME, labels) return labels
def get_cached_labels(self): labels = cache.get(CACHE_NAME, "nada") if labels == "nada": labels = [] labels_qs = self.all().prefetch_related("forums") for label in labels_qs.order_by("name"): label.forums_ids = [f.pk for f in label.forums.all()] labels.append(label) cache.set(CACHE_NAME, labels) return labels
def get_cached_labels(self): labels = cache.get(CACHE_NAME, 'nada') if labels == 'nada': labels = [] labels_qs = self.all().prefetch_related('forums') for label in labels_qs.order_by('name'): label.forums_ids = [f.pk for f in label.forums.all()] labels.append(label) cache.set(CACHE_NAME, labels) return labels
def cache_new_credentials(user, new_email, new_password): new_credentials = { 'user_pk': user.pk, 'email': new_email, 'email_checksum': _make_checksum(user, new_email), 'password': new_password, 'password_checksum': _make_checksum(user, new_password), } cache.set(_make_cache_name(user), new_credentials, CACHE_TIMEOUT) return _make_token(user)
def cache_new_credentials(user, new_email, new_password): new_credentials = { 'user_pk': user.pk, 'email': new_email, 'email_checksum': _make_checksum(user, new_email), 'password': new_password, 'password_checksum': _make_checksum(user, new_password), } cache.set(_make_cache_name(user), new_credentials, CACHE_TIMEOUT) return _make_token(user)
def preload_categories_json(request): cache_key = 'misago_categories_json_{}'.format(request.user.acl_key) categories_json = cache.get(cache_key, 'nada') if categories_json == 'nada': is_root = Q(level=0) is_visible = Q(id__in=request.user.acl_cache['visible_categories']) queryset = Category.objects.all_categories(include_root=True) queryset = queryset.filter(is_root | is_visible) categories_json = BasicCategorySerializer(queryset, many=True).data cache.set(cache_key, categories_json, 15 * 60) request.frontend_context['store']['categories'] = categories_json return {}
def check_version(request): if request.method != "POST": raise Http404() version = cache.get(VERSION_CHECK_CACHE_KEY, 'nada') if version == 'nada': try: api_url = 'https://api.github.com/repos/rafalp/Misago/releases' r = requests.get(api_url) if r.status_code != requests.codes.ok: r.raise_for_status() latest_version = json.loads(r.content)[0]['tag_name'] latest = [int(v) for v in latest_version.split(".")] current = [int(v) for v in __version__.split(".")] for i in range(3): if latest[i] > current[i]: message = _("Outdated: %(current)s < %(latest)s") formats = { 'latest': latest_version, 'current': __version__, } version = { 'is_error': True, 'message': message % formats, } break else: formats = { 'current': __version__, } version = { 'is_error': False, 'message': _("Up to date! (%(current)s)") % formats, } cache.set(VERSION_CHECK_CACHE_KEY, version, 180) except (RequestException, IndexError, KeyError, ValueError): message = _("Failed to connect to GitHub API. Try again later.") version = { 'is_error': True, 'message': message, } return JsonResponse(version)
def get_ranks_online(viewer): viewer_is_listed = viewer.is_authenticated() and viewer.rank.is_on_index cached_online = cache.get(RANKS_CACHE_NAME, 'nada') if viewer_is_listed and ranks_list_missing_viewer(viewer, cached_online): cached_online = 'nada' if cached_online == 'nada': cached_online = get_ranks_from_db(viewer if viewer_is_listed else None) cache.set(RANKS_CACHE_NAME, cached_online, RANKS_CACHE_TIME) if not viewer.acl['can_see_hidden_users']: return filter_visiblity_preference(viewer, cached_online) else: return cached_online
def check_version(request): if not ALLOW_VERSION_CHECK or request.method != "POST": raise Http404() version = cache.get(VERSION_CHECK_CACHE_KEY, 'nada') if version == 'nada': try: api_url = 'https://api.github.com/repos/rafalp/Misago/releases' r = requests.get(api_url) if r.status_code != requests.codes.ok: r.raise_for_status() latest_version = r.json()[0]['tag_name'] latest = parse_version(latest_version) current = parse_version(__version__) if latest > current: version = { 'is_error': True, 'message': _("Outdated: %(current)s! (latest: %(latest)s)") % { 'latest': latest_version, 'current': __version__, }, } else: version = { 'is_error': False, 'message': _("Up to date! (%(current)s)") % { 'current': __version__, }, } cache.set(VERSION_CHECK_CACHE_KEY, version, 180) except (RequestException, IndexError, KeyError, ValueError) as e: version = { 'is_error': True, 'message': _("Failed to connect to GitHub API. Try again later."), } return JsonResponse(version)
def get_parsed_content(setting_name): cache_name = 'misago_legal_%s' % setting_name cached_content = cache.get(cache_name) unparsed_content = settings.get_lazy_setting(setting_name) checksum_source = '%s:%s' % (unparsed_content, settings.SECRET_KEY) unparsed_checksum = md5(checksum_source).hexdigest() if cached_content and cached_content.get('checksum') == unparsed_checksum: return cached_content['parsed'] else: cached_content = { 'checksum': unparsed_checksum, 'parsed': common_flavour(unparsed_content)['parsed_text'], } cache.set(cache_name, cached_content) return cached_content['parsed']
def get_user_acl(user): """get ACL for User""" acl_key = 'acl_%s' % user.acl_key acl_cache = threadstore.get(acl_key) if not acl_cache: acl_cache = cache.get(acl_key) if acl_cache and version.is_valid(acl_cache.get('_acl_version')): return acl_cache else: new_acl = build_acl(user.get_roles()) new_acl['_acl_version'] = version.get_version() threadstore.set(acl_key, new_acl) cache.set(acl_key, new_acl) return new_acl
def get_parsed_content(setting_name): cache_name = 'misago_legal_%s' % setting_name cached_content = cache.get(cache_name) unparsed_content = settings.get_lazy_setting(setting_name) checksum_source = '%s:%s' % (unparsed_content, settings.SECRET_KEY) unparsed_checksum = md5(checksum_source).hexdigest() if cached_content and cached_content.get('checksum') == unparsed_checksum: return cached_content['parsed'] else: cached_content = { 'checksum': unparsed_checksum, 'parsed': common_flavour(unparsed_content)['parsed_text'], } cache.set(cache_name, cached_content) return cached_content['parsed']
def check_version(request): if request.method != "POST": raise Http404() version = cache.get(VERSION_CHECK_CACHE_KEY, 'nada') if version == 'nada': try: api_url = 'https://api.github.com/repos/rafalp/Misago/releases' r = requests.get(api_url) if r.status_code != requests.codes.ok: r.raise_for_status() latest_version = json.loads(r.content)[0]['tag_name'] latest = [int(v) for v in latest_version.split(".")] current = [int(v) for v in __version__.split(".")] for i in xrange(3): if latest[i] > current[i]: message = _("Outdated: %(current)s < %(latest)s") formats = { 'latest': latest_version, 'current': __version__ } version = { 'is_error': True, 'message': message % formats } break else: formats = {'current': __version__} version = { 'is_error': False, 'message': _("Up to date! (%(current)s)") % formats, } cache.set(VERSION_CHECK_CACHE_KEY, version, 180) except (RequestException, IndexError, KeyError, ValueError): message = _("Failed to connect to GitHub API. Try again later.") version = { 'is_error': True, 'message': message } return JsonResponse(version)
def check_version(request): if not ALLOW_VERSION_CHECK or request.method != "POST": raise Http404() version = cache.get(VERSION_CHECK_CACHE_KEY, 'nada') if version == 'nada': try: api_url = 'https://api.github.com/repos/rafalp/Misago/releases' r = requests.get(api_url) if r.status_code != requests.codes.ok: r.raise_for_status() latest_version = r.json()[0]['tag_name'] latest = parse_version(latest_version) current = parse_version(__version__) if latest > current: version = { 'is_error': True, 'message': _("Outdated: %(current)s! (latest: %(latest)s)") % { 'latest': latest_version, 'current': __version__, }, } else: version = { 'is_error': False, 'message': _("Up to date! (%(current)s)") % { 'current': __version__, }, } cache.set(VERSION_CHECK_CACHE_KEY, version, 180) except (RequestException, IndexError, KeyError, ValueError) as e: version = { 'is_error': True, 'message': _("Failed to connect to GitHub API. Try again later."), } return JsonResponse(version)
def check_version(request): if request.method != "POST": raise Http404() version = cache.get(VERSION_CHECK_CACHE_KEY, 'nada') if version == 'nada': try: api_url = 'https://pypi.org/pypi/Misago/json' r = requests.get(api_url) r.raise_for_status() latest_version = r.json()['info']['version'] if latest_version == __version__: version = { 'is_error': False, 'message': _("Up to date! (%(current)s)") % { 'current': __version__, }, } else: version = { 'is_error': True, 'message': _("Outdated: %(current)s! (latest: %(latest)s)") % { 'latest': latest_version, 'current': __version__, }, } cache.set(VERSION_CHECK_CACHE_KEY, version, 180) except (RequestException, IndexError, KeyError, ValueError) as e: version = { 'is_error': True, 'message': _("Failed to connect to pypi.org API. Try again later."), } return JsonResponse(version)
def get_parsed_agreement_text(request, agreement): if not agreement.text: return None cache_name = 'misago_legal_%s_%s' % (agreement.pk, agreement.last_modified_on or '') cached_content = cache.get(cache_name) unparsed_content = agreement.text checksum_source = force_bytes('%s:%s' % (unparsed_content, settings.SECRET_KEY)) unparsed_checksum = md5(checksum_source).hexdigest() if cached_content and cached_content.get('checksum') == unparsed_checksum: return cached_content['parsed'] else: parsed = common_flavour(request, None, unparsed_content)['parsed_text'] cached_content = { 'checksum': unparsed_checksum, 'parsed': parsed, } cache.set(cache_name, cached_content) return cached_content['parsed']
def get_cached_categories_dict(self): categories_dict = cache.get(CACHE_NAME, 'nada') if categories_dict == 'nada': categories_dict = self.get_categories_dict_from_db() cache.set(CACHE_NAME, categories_dict) return categories_dict
def get_agreements(self): agreements = self.get_agreements_from_cache() if agreements == 'nada': agreements = self.get_agreements_from_db() cache.set(CACHE_KEY, agreements) return agreements
def get_cached_forums_dict(self): forums_dict = cache.get(CACHE_NAME, 'nada') if forums_dict == 'nada': forums_dict = self.get_forums_dict_from_db() cache.set(CACHE_NAME, forums_dict) return forums_dict
def get_cached_forums_dict(self): forums_dict = cache.get(CACHE_NAME, 'nada') if forums_dict == 'nada': forums_dict = self.get_forums_dict_from_db() cache.set(CACHE_NAME, forums_dict) return forums_dict
def get_levels_from_cache(self): levels = cache.get(CACHE_NAME, 'nada') if levels == 'nada': levels = self.get_levels_from_database() cache.set(CACHE_NAME, levels) return levels
def get_levels_from_cache(self): levels = cache.get(CACHE_NAME, "nada") if levels == "nada": levels = self.get_levels_from_database() cache.set(CACHE_NAME, levels) return levels
def get_users_count(self): users_count = cache.get('users_count') if not users_count: users_count = self.queryset.count() cache.set('users_count', users_count, 15 * 60) return users_count
def get_cached_categories_dict(self): categories_dict = cache.get(CACHE_NAME, 'nada') if categories_dict == 'nada': categories_dict = self.get_categories_dict_from_db() cache.set(CACHE_NAME, categories_dict) return categories_dict
def get_users_count(self): users_count = cache.get('users_count') if not users_count: users_count = self.queryset.count() cache.set('users_count', users_count, 15 * 60) return users_count