fix cf firewall rules with cursor, remove mmap

This commit is contained in:
Benny
2023-03-20 19:12:25 +01:00
parent 97a6223965
commit 0203fd1a93
6 changed files with 44 additions and 51 deletions

View File

@@ -14,10 +14,11 @@ import requests
from bson import ObjectId
from captcha.image import ImageCaptcha
from common.utils import ts_date
from databases import cf
from common.utils import Cloudflare, ts_date
from databases.base import Mongo, Redis
cf = Cloudflare()
captcha_ex = 60 * 10
predefined_str = re.sub(r"[1l0oOI]", "", string.ascii_letters + string.digits)
@@ -77,12 +78,7 @@ class Category(Mongo):
query_dict[f"data.info.{key}"] = value
logging.info("Query dict %s", query_dict)
projection = {"_id": False, "data.list": False}
data = (
self.db["yyets"]
.find(query_dict, projection=projection)
.limit(size)
.skip((page - 1) * size)
)
data = self.db["yyets"].find(query_dict, projection=projection).limit(size).skip((page - 1) * size)
count = self.db["yyets"].count_documents(query_dict)
f = []
for item in data:
@@ -91,9 +87,7 @@ class Category(Mongo):
{"resourceId": item["data"]["info"]["id"]}, projection=projection
)
if douban_data:
douban_data["posterData"] = base64.b64encode(
douban_data["posterData"]
).decode("u8")
douban_data["posterData"] = base64.b64encode(douban_data["posterData"]).decode("u8")
item["data"]["info"]["douban"] = douban_data
else:
item["data"]["info"]["douban"] = {}
@@ -152,11 +146,7 @@ class Other(Mongo):
self.db["history"].insert_one(json_data)
# save all the views data to history
projection = {"_id": False, "data.info.views": True, "data.info.id": True}
data = (
self.db["yyets"]
.find({}, projection)
.sort("data.info.views", pymongo.DESCENDING)
)
data = self.db["yyets"].find({}, projection).sort("data.info.views", pymongo.DESCENDING)
result = {"date": last_month, "type": "detail"}
for datum in data:
rid = str(datum["data"]["info"]["id"])
@@ -167,9 +157,7 @@ class Other(Mongo):
self.db["yyets"].update_many({}, {"$set": {"data.info.views": 0}})
def import_ban_user(self):
usernames = self.db["users"].find(
{"status.disable": True}, projection={"username": True}
)
usernames = self.db["users"].find({"status.disable": True}, projection={"username": True})
r = Redis().r
r.delete("user_blacklist")
logging.info("Importing ban users to redis...%s", usernames)
@@ -184,9 +172,7 @@ class Captcha(Redis):
image = ImageCaptcha()
data = image.generate(chars)
self.r.set(captcha_id, chars, ex=captcha_ex)
return (
f"data:image/png;base64,{base64.b64encode(data.getvalue()).decode('ascii')}"
)
return f"data:image/png;base64,{base64.b64encode(data.getvalue()).decode('ascii')}"
def verify_code(self, user_input, captcha_id) -> dict:
correct_code = self.r.get(captcha_id)