def clear_cache_by_user_and_activity_id(cls, user_id, activity_id): mc.delete( cls.cache_count_by_user_and_activity_id_key.format( user_id=user_id, activity_id=activity_id)) mc.delete( cls.cache_ids_by_user_and_activity_id_key.format( user_id=user_id, activity_id=activity_id))
def clear_income_user_cache_by_date(day): sql = 'select id from funcombo_income_user where day=%s' params = (day,) rs = db.execute(sql, params) if rs: for user_id in rs[0]: mc.delete(FUND_INCOMEUSER_CACHE_KEY % (user_id,))
def validate(cls, text, secret, delete=True): strs = cls.get(secret) if not strs: raise OutdatedCaptchaError() if text != strs: raise WrongCaptchaError() if delete: mc.delete(_MC_CAPTCHA_KEY % secret)
def clear_cache(self): mc.delete(ARTICLE_CACHE_KEY % (self.id)) for name, status in STATUS.items(): mc.delete(ARTICLE_ALL_CACHE_KEY % (self.type, status)) mc.delete(ARTICLE_ALL_TYPE_CACHE_KEY % (status)) mc.delete(ARTICLE_COUNT_CACHE_KEY % (self.type, status)) mc.delete(ARTICLE_CATE_CACHE_KEY % (self.type, self.category, status))
def update(cls, code, url): ''' 根据 code 更新短网址 ''' db.execute('update shorten_url set url=%s where code=%s', (url, code)) db.commit() mc.delete(_SHORTEN_URL_MC_KEY % code) return True
def add(cls, type, rec_rank=RECOMMEND_RANK.ONE, status=PRODUCT_STATUS.ON): id = db.execute('insert into ' + cls._table + ' ' '(`type`, status, rec_rank) values ' '(%s, %s, %s)', (type, status, rec_rank)) if id: db.commit() for k, v in PRODUCT_STATUS.items(): mc.delete(_ALL_PRODUCT_CACHE_KEY % (cls.kind, v)) mc.delete(_PRODUCT_CACHE_KEY % (cls.kind, id)) return str(id)
def clear_cache(self): mc.delete(self.cache_key.format(asset_id=self.id_)) mc.delete(self.user_id_cache_key.format(user_id=self.user_id)) mc.delete( self.user_cache_key.format(user_id=self.user_id, product_id=self.product_id)) mc.delete( self.order_code_cache_key.format(order_code=self.order_code, product_id=self.product_id)) mc.delete(self.product_cache_key.format(product_id=self.product_id))
def start_date(self, value): if not value or self._start_date: return self._start_date = value sql = ('update funcombo_userlike set start_date=%s' ' where user_id=%s and group_id=%s and start_date is NULL') params = (self._start_date, self.user_id, self.group_id) db.execute(sql, params) db.commit() mc.delete(FUND_LIKE_USER_CACHE_KEY % (self.user_id, ))
def remove_fund(cls, group, fund): try: db.execute( 'delete from funcombo_group_fund ' ' where group_id = %s and fund_code = %S', (group.id, fund.code)) db.commit() mc.delete(FUND_GFM2M_GROUP_CACHE_PRFIX % (group.id, )) return True except IntegrityError: db.rollback() warn('remove fund from group failed') return False
def update(self, rate, reason): try: db.execute( 'update funcombo_group_fund set ' 'rate = %s,' 'reason = %s,' 'where id = %s', (rate, reason, self.id)) db.commit() mc.delete(FUND_GFM2M_CACHE_PRFIX % (self.id, )) return self.get(self.id) except IntegrityError: db.rollback() warn('update funcombo_group_fund_m2m failed')
def add_fund(cls, group, fund, reason, rate=0.2): try: id = db.execute( 'insert into funcombo_group_fund ' '(group_id, fund_code, rate, reason)' 'values(%s, %s, %s, %s)', (group.id, fund.code, rate, reason)) if id: db.commit() mc.delete(FUND_GFM2M_GROUP_CACHE_PRFIX % (group.id, )) p = cls.get(id) return p else: db.rollback() except IntegrityError: db.rollback() warn('add fund to group failed')
def add(cls, group_id, user_id, day, income): from .group import Group group = Group.get(group_id) if not group: warn('group %d not found' % (group_id, )) return False try: id = db.execute( 'insert into funcombo_income_user ' '(group_id, user_id, day, income) ' 'values(%s, %s, %s, %s)', (group_id, user_id, day, income)) db.commit() mc.delete(FUND_INCOMEUSER_CACHE_KEY % (id, )) p = cls.get(id) return p except IntegrityError: db.rollback() warn('insert funcombo_income_user failed')
def like_group(cls, group_id, user_id): from .group import Group group = Group.get(group_id) if not group: warn('group %d not found' % (group_id, )) return False if Subscription.is_like(group_id, user_id): return False id = db.execute( 'insert into funcombo_userlike ' ' (group_id, user_id, create_time) ' ' values ' ' (%s, %s, %s)', (group_id, user_id, datetime.now())) db.commit() mc.delete(FUND_LIKE_USER_CACHE_KEY % (user_id, )) mc.delete(FUND_LIKE_USERCOUNT_CACHE_KEY) return id
def add(cls, subject, subtitle, subtitle2, description, create_time, update_time, reason, highlight, reason_update, related): params = (subject, subtitle, subtitle2, description, create_time, update_time, reason, highlight, reason_update, related) try: id = db.execute( 'insert into funcombo_group ' '(subject, subtitle, subtitle2, description, ' ' create_time, update_time, reason, highlight, reason_update, related) ' 'values(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', params) if id: db.commit() mc.delete(FUND_GROUP_IDS_CACHE_KEY) p = cls.get(id) return p else: db.rollback() except IntegrityError: db.rollback() warn('insert funcombo_group failed')
def add(cls, plan_id, rev): if not plan_id or not rev: return False name = randbytes2(8) try: params = (name, plan_id, rev, FORMULA_VER, REPORT_STATUS.new, datetime.now()) id = db.execute('insert into user_report ' '(confuse_name, plan_id, rev, formula_ver, status,' ' create_time) ' 'values(%s, %s, %s, %s, %s, %s)', params) if id: db.commit() mc.delete(REPORT_PLAN_IDS_CACHE_KEY % plan_id) return cls.get(id) else: db.rollback() except IntegrityError: db.rollback() warn('insert account failed')
def clear_cache_by_user(cls, user_id): mc.delete(cls.cache_key_by_user_id.format(user_id=user_id)) mc.delete( cls.cache_key_by_user_and_status.format(user_id=user_id, status=cls.Status.active)) mc.delete( cls.cache_key_by_user_and_status.format( user_id=user_id, status=cls.Status.inactive))
def update(self, subject, subtitle, subtitle2, description, reason, highlight, reason_update, related): params = (subject, subtitle, subtitle2, description, reason, highlight, reason_update, related, datetime.now(), self.id) try: db.execute( 'update funcombo_group set ' 'subject = %s,' 'subtitle = %s,' 'subtitle2 = %s,' 'description = %s,' 'reason = %s,' 'highlight = %s,' 'reason_update = %s,' 'related = %s,' 'update_time = %s ' 'where id = %s', params) db.commit() mc.delete(FUND_GROUP_CACHE_KEY % (self.id, )) return self.get(self.id) except IntegrityError: db.rollback() warn('update funcombo_group failed')
def add(cls, group_id, day, net_worth, income, income_stock): from .group import Group group = Group.get(group_id) if not group: warn('group %d not found' % (group_id, )) return False if isinstance(day, datetime): day = day.date() try: id = db.execute( 'insert into funcombo_income ' '(group_id, day, net_worth, income, income_stock) ' 'values(%s, %s, %s, %s, %s)', (group_id, day, net_worth, income, income_stock)) if id: db.commit() mc.delete(FUND_INCOME_LEASTMORE_CACHE_KEY % (group_id, )) p = cls.get(id) return p else: db.rollback() except IntegrityError: db.rollback() warn('insert funcombo_income failed')
def clear_local_sold_amount_cache(cls, raw_product_id, wrapped_product_id): mc.delete( cls.raw_product_sold_amount_cache_key.format( raw_product_id=raw_product_id)) mc.delete( cls.wrapped_product_sold_amount_cache_key.format( raw_product_id=raw_product_id, wrapped_product_id=None)) mc.delete( cls.wrapped_product_sold_amount_cache_key.format( raw_product_id=raw_product_id, wrapped_product_id=wrapped_product_id))
def clear_all_ids_cache(cls): mc.delete(cls.all_ids_cache_key)
def clear_cache(cls, account_id): mc.delete(cls.cache_by_local_key.format(account_id=account_id))
def clear_package_coupon_ids_cache(cls, package_id): mc.delete(cls.cache_package_coupon_ids_key.format(**locals()))
def clear_user_coupon_ids_cache(cls, user_id): mc.delete(cls.cache_user_coupon_ids_key.format(**locals()))
def clear_cache(cls, id_): mc.delete(cls.cache_coupon_key.format(**locals()))
def clear_cache_by_project(cls, project_id): mc.delete(cls.cache_key_by_project.format(**locals()))
def clear_cache(cls, user_id): mc.delete(cls.cache_records_count_by_user_key.format(**locals()))
def clear_product_by_kind_and_raw_cache(cls, kind_id, raw_product_id): mc.delete(cls.product_by_kind_and_raw_id_cache_key.format(**locals()))
def clear_product_ids_by_raw_id_cache(cls, raw_id): mc.delete(cls.product_ids_by_raw_id_cache_key.format(**locals()))
def clear_cache(cls, product_id): mc.delete(cls.cache_key.format(product_id=product_id)) p = cls.get(product_id) if p: mc.delete(cls.cache_by_vendor.format(vendor_id=p.vendor_id))
def clear_cache(cls, account_id): mc.delete(INSURE_61_CACHE_KEY.format(account_id=account_id))