draft-seo-handling
All checks were successful
Deploy on push / deploy (push) Successful in 1m10s

This commit is contained in:
Untone 2025-04-15 20:16:01 +03:00
parent bd129efde6
commit eb216a5f36
5 changed files with 30 additions and 30 deletions

View File

@ -1,8 +1,8 @@
import time
from operator import or_
from sqlalchemy.sql import and_
import trafilatura
from sqlalchemy.sql import and_
from cache.cache import (
cache_author,
@ -117,7 +117,7 @@ async def create_draft(_, info, draft_input):
del draft_input["id"]
if "seo" not in draft_input and not draft_input["seo"]:
body_teaser = draft_input.get("body", "")[:300].split('\n')[:-1].join("\n")
body_teaser = draft_input.get("body", "")[:300].split("\n")[:-1].join("\n")
draft_input["seo"] = draft_input.get("lead", body_teaser)
# Добавляем текущее время создания
@ -170,7 +170,7 @@ async def update_draft(_, info, draft_id: int, draft_input):
body_text = trafilatura.extract(body_src)
lead_src = draft_input["lead"] if "lead" in draft_input else draft.lead
lead_text = trafilatura.extract(lead_src)
body_teaser = body_text[:300].split('. ')[:-1].join(".\n")
body_teaser = body_text[:300].split(". ")[:-1].join(".\n")
draft_input["seo"] = lead_text or body_teaser
Draft.update(draft, draft_input)

View File

@ -1,6 +1,7 @@
import time
import orjson
import trafilatura
from sqlalchemy import and_, desc, select
from sqlalchemy.orm import joinedload
from sqlalchemy.sql.functions import coalesce
@ -22,7 +23,6 @@ from services.notify import notify_shout
from services.schema import query
from services.search import search_service
from utils.logger import root_logger as logger
import trafilatura
async def cache_by_id(entity, entity_id: int, cache_method):
@ -181,7 +181,7 @@ async def create_shout(_, info, inp):
lead = inp.get("lead", "")
body_text = trafilatura.extract(body)
lead_text = trafilatura.extract(lead)
seo = inp.get("seo", lead_text or body_text[:300].split('. ')[:-1].join(". "))
seo = inp.get("seo", lead_text or body_text[:300].split(". ")[:-1].join(". "))
new_shout = Shout(
slug=slug,
body=body,
@ -388,7 +388,7 @@ def patch_topics(session, shout, topics_input):
# @login_required
async def update_shout(_, info, shout_id: int, shout_input=None, publish=False):
logger.info(f"Starting update_shout with id={shout_id}, publish={publish}")
logger.debug(f"Full shout_input: {shout_input}") # DraftInput
logger.debug(f"Full shout_input: {shout_input}") # DraftInput
user_id = info.context.get("user_id")
roles = info.context.get("roles", [])

View File

@ -6,7 +6,7 @@ from cache.cache import (
get_cached_topic_authors,
get_cached_topic_by_slug,
get_cached_topic_followers,
invalidate_cache_by_prefix
invalidate_cache_by_prefix,
)
from orm.author import Author
from orm.topic import Topic
@ -149,7 +149,6 @@ async def get_topics_with_stats(limit=100, offset=0, community_id=None, by=None)
"""
comments_stats = {row[0]: row[1] for row in session.execute(text(comments_stats_query))}
# Формируем результат с добавлением статистики
result = []
for topic in topics:
@ -158,7 +157,7 @@ async def get_topics_with_stats(limit=100, offset=0, community_id=None, by=None)
"shouts": shouts_stats.get(topic.id, 0),
"followers": followers_stats.get(topic.id, 0),
"authors": authors_stats.get(topic.id, 0),
"comments": comments_stats.get(topic.id, 0)
"comments": comments_stats.get(topic.id, 0),
}
result.append(topic_dict)

View File

@ -30,6 +30,7 @@ class ViewedStorage:
Класс для хранения и доступа к данным о просмотрах.
Использует Redis в качестве основного хранилища и Google Analytics для сбора новых данных.
"""
lock = asyncio.Lock()
views_by_shout = {}
shouts_by_topic = {}