precommit
All checks were successful
Deploy on push / deploy (push) Successful in 49s

This commit is contained in:
Untone 2024-04-08 10:38:58 +03:00
parent df15e63dde
commit c301256751
24 changed files with 92 additions and 188 deletions

View File

@ -12,7 +12,7 @@ repos:
- id: check-merge-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
rev: v0.3.5
hooks:
- id: ruff
args: [--fix]

View File

@ -1,3 +1,8 @@
[0.3.3]
- feat: sentry integration enabled
- fix: reindex on update shout
- packages upgrade, isort
[0.3.2]
- redis cache for what author follows
- redis cache for followers

View File

@ -3,8 +3,8 @@ import time
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from services.db import Base
from orm.author import Author
from services.db import Base
class CommunityAuthor(Base):

View File

@ -3,11 +3,11 @@ import time
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from services.db import Base
from orm.community import Community
from orm.author import Author
from orm.community import Community
from orm.reaction import Reaction
from orm.topic import Topic
from services.db import Base
class ShoutTopic(Base):

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "core"
version = "0.3.2"
version = "0.3.3"
description = "core module for discours.io"
authors = ["discoursio devteam"]
license = "MIT"
@ -8,79 +8,26 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.12"
SQLAlchemy = "^2.0.22"
SQLAlchemy = "^2.0.29"
psycopg2-binary = "^2.9.9"
redis = {extras = ["hiredis"], version = "^5.0.1"}
sentry-sdk = { version = "^1.4.1", extras = ["starlette", "ariadne", "sqlalchemy"] }
starlette = "^0.36.1"
gql = "^3.4.1"
ariadne = "^0.21"
pre-commit = "^3.6.0"
granian = "^1.0.1"
google-analytics-data = "^0.18.3"
opensearch-py = "^2.4.2"
httpx = "^0.26.0"
sentry-sdk = {version = "^1.44.1", extras = ["starlette", "ariadne", "sqlalchemy"]}
starlette = "^0.37.2"
gql = "^3.5.0"
ariadne = "^0.23.0"
pre-commit = "^3.7.0"
granian = "^1.2.1"
google-analytics-data = "^0.18.7"
opensearch-py = "^2.5.0"
httpx = "^0.27.0"
dogpile-cache = "^1.3.1"
colorlog = "^6.8.2"
sqlalchemy-searchable = "^2.1.0"
[tool.poetry.group.dev.dependencies]
ruff = "^0.2.1"
ruff = "^0.3.5"
isort = "^5.13.2"
pyright = "^1.1.350"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.isort]
multi_line_output = 3
include_trailing_comma = false
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 120
[lint]
select = ["E4", "E7", "E9", "F"]
ignore = []
line-length = 120
target-version = "py312"
[tool.ruff.format]
# Prefer single quotes over double quotes.
quote-style = "single"
skip-magic-trailing-comma = true
[tool.pyright]
venvPath = "."
venv = ".venv"
include = ["."]
useLibraryCodeForTypes = false
disableLanguageServices = false
disableOrganizeImports = false
reportMissingImports = true
reportMissingModuleSource = "warning"
reportImportCycles = "warning"
maxMemoryForLargeFile = 4096
pythonVersion = "3.12"
autoImportCompletions = true
useVirtualEnv = true
typeCheckingMode = "basic"
disableJediCompletion = true
disableCompletion = false
disableSnippetCompletion = false
disableGoToDefinition = false
disableRenaming = false
disableSignatureHelp = false
diagnostics = true
logLevel = "debug"
pluginSearchPaths = []
typings = {}
mergeTypeStubPackages = false
[tool.pytest.ini_options]
pythonpath = ["."]
[tool.pytest]
python_files = "*_test.py"

View File

@ -1,54 +1,24 @@
from resolvers.author import (
get_author,
get_author_follows,
get_author_follows_topics,
get_author_follows_authors,
get_author_followers,
get_author_id,
get_authors_all,
load_authors_by,
update_author,
search_authors,
)
from resolvers.rating import rate_author
from resolvers.author import (get_author, get_author_followers,
get_author_follows, get_author_follows_authors,
get_author_follows_topics, get_author_id,
get_authors_all, load_authors_by, search_authors,
update_author)
from resolvers.community import get_communities_all, get_community
from resolvers.editor import create_shout, delete_shout, update_shout
from resolvers.follower import (
follow,
unfollow,
get_topic_followers,
get_shout_followers,
)
from resolvers.reaction import (
create_reaction,
delete_reaction,
load_reactions_by,
load_shouts_followed,
update_reaction,
)
from resolvers.reader import (
get_shout,
load_shouts_by,
load_shouts_feed,
load_shouts_random_top,
load_shouts_random_topic,
load_shouts_search,
load_shouts_unrated,
)
from resolvers.topic import (
get_topic,
get_topics_all,
get_topics_by_author,
get_topics_by_community,
)
from resolvers.notifier import (
load_notifications,
notification_mark_seen,
notifications_seen_after,
notifications_seen_thread,
)
from resolvers.follower import (follow, get_shout_followers,
get_topic_followers, unfollow)
from resolvers.notifier import (load_notifications, notification_mark_seen,
notifications_seen_after,
notifications_seen_thread)
from resolvers.rating import rate_author
from resolvers.reaction import (create_reaction, delete_reaction,
load_reactions_by, load_shouts_followed,
update_reaction)
from resolvers.reader import (get_shout, load_shouts_by, load_shouts_feed,
load_shouts_random_top, load_shouts_random_topic,
load_shouts_search, load_shouts_unrated)
from resolvers.topic import (get_topic, get_topics_all, get_topics_by_author,
get_topics_by_community)
from services.cache import events_register
events_register()

View File

@ -2,27 +2,23 @@ import asyncio
import json
import time
from sqlalchemy import select, or_, and_, text, desc
from sqlalchemy import and_, desc, or_, select, text
from sqlalchemy.orm import aliased
from sqlalchemy_searchable import search
from orm.author import Author, AuthorFollower
from orm.shout import ShoutAuthor, ShoutTopic
from orm.topic import Topic
from resolvers.stat import (
get_authors_with_stat_cached,
author_follows_authors,
author_follows_topics,
get_with_stat,
)
from services.cache import set_author_cache, update_author_followers_cache
from resolvers.stat import (author_follows_authors, author_follows_topics,
get_authors_with_stat_cached, get_with_stat)
from services.auth import login_required
from services.cache import set_author_cache, update_author_followers_cache
from services.db import local_session
from services.encoders import CustomJSONEncoder
from services.logger import root_logger as logger
from services.memorycache import cache_region
from services.rediscache import redis
from services.schema import mutation, query
from services.logger import root_logger as logger
@mutation.field('update_author')

View File

@ -5,8 +5,8 @@ from orm.author import Author
from orm.community import Community, CommunityAuthor
from orm.shout import ShoutCommunity
from services.db import local_session
from services.schema import query
from services.logger import root_logger as logger
from services.schema import query
def add_community_stat_columns(q):

View File

@ -1,6 +1,6 @@
import time
from sqlalchemy import and_, select, desc
from sqlalchemy import and_, desc, select
from sqlalchemy.orm import joinedload
from sqlalchemy.sql.functions import coalesce
@ -13,10 +13,10 @@ from resolvers.follower import reactions_follow, reactions_unfollow
from services.auth import login_required
from services.db import local_session
from services.diff import apply_diff, get_diff
from services.logger import root_logger as logger
from services.notify import notify_shout
from services.schema import mutation, query
from services.search import search_service
from services.logger import root_logger as logger
@query.field('get_my_shout')

View File

@ -3,33 +3,26 @@ import time
from typing import List
from psycopg2.errors import UniqueViolation
from sqlalchemy import select, or_
from sqlalchemy import or_, select
from sqlalchemy.sql import and_
from orm.author import Author, AuthorFollower
from orm.community import Community
# from orm.community import Community
from orm.reaction import Reaction
from orm.shout import Shout, ShoutReactionsFollower
from orm.topic import Topic, TopicFollower
from resolvers.stat import (
get_authors_with_stat_cached,
author_follows_topics,
author_follows_authors,
get_topics_with_stat_cached,
)
from resolvers.stat import (author_follows_authors, author_follows_topics,
get_authors_with_stat_cached,
get_topics_with_stat_cached)
from services.auth import login_required
from services.cache import (DEFAULT_FOLLOWS, update_followers_for_author,
update_follows_for_author)
from services.db import local_session
from services.cache import (
DEFAULT_FOLLOWS,
update_follows_for_author,
update_followers_for_author,
)
from services.notify import notify_follower
from services.schema import mutation, query
from services.logger import root_logger as logger
from services.notify import notify_follower
from services.rediscache import redis
from services.schema import mutation, query
@mutation.field('follow')

View File

@ -2,24 +2,19 @@ import json
import time
from typing import List, Tuple
from sqlalchemy.exc import SQLAlchemyError
from orm.author import Author
from orm.shout import Shout
from services.auth import login_required
from services.schema import mutation, query
from sqlalchemy import and_, select
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm import aliased
from sqlalchemy.sql import not_
from orm.notification import (
Notification,
NotificationAction,
NotificationEntity,
NotificationSeen,
)
from orm.author import Author
from orm.notification import (Notification, NotificationAction,
NotificationEntity, NotificationSeen)
from orm.shout import Shout
from services.auth import login_required
from services.db import local_session
from services.logger import root_logger as logger
from services.schema import mutation, query
def query_notifications(

View File

@ -1,7 +1,7 @@
from sqlalchemy import and_, func, case, true, select
from sqlalchemy import and_, case, func, select, true
from sqlalchemy.orm import aliased
from orm.author import AuthorRating, Author
from orm.author import Author, AuthorRating
from orm.reaction import Reaction, ReactionKind
from orm.shout import Shout
from services.auth import login_required

View File

@ -1,7 +1,7 @@
import time
from typing import List
from sqlalchemy import and_, case, desc, func, select, text, asc
from sqlalchemy import and_, asc, case, desc, func, select, text
from sqlalchemy.orm import aliased, joinedload
from sqlalchemy.sql import union
@ -13,10 +13,10 @@ from resolvers.editor import handle_proposing
from resolvers.follower import reactions_follow
from services.auth import add_user_role, login_required
from services.db import local_session
from services.logger import root_logger as logger
from services.notify import notify_reaction
from services.schema import mutation, query
from services.viewed import ViewedStorage
from services.logger import root_logger as logger
def add_reaction_stat_columns(q, aliased_reaction):

View File

@ -1,6 +1,7 @@
from sqlalchemy import bindparam, distinct, or_, text
from sqlalchemy.orm import aliased, joinedload
from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select
from sqlalchemy.sql.expression import (and_, asc, case, desc, func, nulls_last,
select)
from orm.author import Author, AuthorFollower
from orm.reaction import Reaction, ReactionKind
@ -10,10 +11,10 @@ from resolvers.reaction import add_reaction_stat_columns
from resolvers.topic import get_topics_random
from services.auth import login_required
from services.db import local_session
from services.logger import root_logger as logger
from services.schema import query
from services.search import search_text
from services.viewed import ViewedStorage
from services.logger import root_logger as logger
def query_shouts():

View File

@ -1,14 +1,14 @@
import json
from sqlalchemy import func, distinct, select, join, and_
from sqlalchemy import and_, distinct, func, join, select
from sqlalchemy.orm import aliased
from orm.author import Author, AuthorFollower
from orm.reaction import Reaction, ReactionKind
from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.topic import Topic, TopicFollower
from resolvers.rating import add_author_rating_columns
from orm.topic import TopicFollower, Topic
from services.db import local_session
from orm.author import AuthorFollower, Author
from orm.shout import ShoutTopic, ShoutAuthor, Shout
from services.logger import root_logger as logger
from services.rediscache import redis

View File

@ -6,8 +6,8 @@ from orm.topic import Topic
from resolvers.stat import get_topics_with_stat_cached, get_with_stat
from services.auth import login_required
from services.db import local_session
from services.schema import mutation, query
from services.memorycache import cache_region
from services.schema import mutation, query
@query.field('get_topics_all')

View File

@ -1,9 +1,9 @@
from granian.constants import Interfaces
from granian.server import Granian
from services.logger import root_logger as logger
from settings import PORT
if __name__ == '__main__':
logger.info('started')

View File

@ -1,4 +1,5 @@
from functools import wraps
import httpx
from starlette.exceptions import HTTPException

View File

@ -1,17 +1,16 @@
import asyncio
from sqlalchemy import select, event
import json
from sqlalchemy import event, select
from orm.author import Author, AuthorFollower
from orm.reaction import Reaction
from orm.shout import ShoutAuthor, Shout
from orm.shout import Shout, ShoutAuthor
from orm.topic import Topic, TopicFollower
from resolvers.stat import get_with_stat
from services.encoders import CustomJSONEncoder
from services.rediscache import redis
from services.logger import root_logger as logger
from services.rediscache import redis
DEFAULT_FOLLOWS = {
'topics': [],

View File

@ -1,10 +1,12 @@
import json
import math
import time
import traceback
import warnings
from typing import Any, Callable, Dict, TypeVar
from sqlalchemy import exc, event, Engine
from sqlalchemy import inspect, Column, Integer, create_engine, JSON
from sqlalchemy import (JSON, Column, Engine, Integer, create_engine, event,
exc, inspect)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session, configure_mappers
from sqlalchemy.sql.schema import Table
@ -12,8 +14,6 @@ from sqlalchemy_searchable import make_searchable
from services.logger import root_logger as logger
from settings import DB_URL
import warnings
import traceback
# Подключение к базе данных SQLAlchemy
engine = create_engine(DB_URL, echo=False, pool_size=10, max_overflow=20)

View File

@ -1,4 +1,5 @@
import logging
import colorlog
# Define the color scheme

View File

@ -1,9 +1,9 @@
import logging
import redis.asyncio as aredis
import logging
from settings import REDIS_URL
# Set redis logging level to suppress DEBUG messages
logger = logging.getLogger('redis')
logger.setLevel(logging.WARNING)

View File

@ -7,12 +7,8 @@ from typing import Dict
# ga
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import (
DateRange,
Dimension,
Metric,
RunReportRequest,
)
from google.analytics.data_v1beta.types import (DateRange, Dimension, Metric,
RunReportRequest)
from orm.author import Author
from orm.shout import Shout, ShoutAuthor, ShoutTopic

View File

@ -2,9 +2,9 @@ import os
import re
from starlette.endpoints import HTTPEndpoint
from starlette.exceptions import HTTPException
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette.exceptions import HTTPException
from orm.author import Author
from services.db import local_session