Skip to content

Commit

Permalink
连接池
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyThink committed Aug 26, 2023
1 parent c62c47f commit 7f44683
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
16 changes: 15 additions & 1 deletion yyetsweb/databases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
# 2023-03-17 18:57

import logging
import os
import pathlib
import sys

import pymongo

DOUBAN_SEARCH = "https://www.douban.com/search?cat=1002&q={}"
DOUBAN_DETAIL = "https://movie.douban.com/subject/{}/"

Expand All @@ -17,6 +20,17 @@
from fansub import BD2020, XL720, NewzmzOnline, ZhuixinfanOnline, ZimuxiaOnline

logging.info(
"Loading fansub...%s",
"Initialized: loading fansub...%s",
(BD2020, XL720, NewzmzOnline, ZhuixinfanOnline, ZimuxiaOnline),
)

client = pymongo.MongoClient(
host=os.getenv("MONGO", "localhost"),
connect=True,
connectTimeoutMS=5000,
serverSelectionTimeoutMS=5000,
maxPoolSize=300,
minPoolSize=50,
maxIdleTimeMS=600000,
)
db = client["zimuzu"]
15 changes: 3 additions & 12 deletions yyetsweb/databases/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,16 @@

import fakeredis
import meilisearch
import pymongo
import redis

from databases import db

faker_redis = fakeredis.FakeStrictRedis()


class Mongo:
def __init__(self):
self.client = pymongo.MongoClient(
host=os.getenv("MONGO", "localhost"),
connect=False,
connectTimeoutMS=5000,
serverSelectionTimeoutMS=5000,
)
self.db = self.client["zimuzu"]
super().__init__()

def __del__(self):
self.client.close()
self.db = db

def is_admin(self, username: str) -> bool:
data = self.db["users"].find_one({"username": username, "group": {"$in": ["admin"]}})
Expand Down

0 comments on commit 7f44683

Please sign in to comment.