mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
increase speed of mysql when searching posts
This commit is contained in:
@@ -19,6 +19,7 @@ using Telegram.Bot.Types.Enums;
|
||||
using Feed = Kruzya.TelegramBot.RichSiteSummary.Data.Feed;
|
||||
|
||||
using CodeHollow.FeedReader.Feeds;
|
||||
using Kruzya.TelegramBot.Core.Service;
|
||||
|
||||
namespace Kruzya.TelegramBot.RichSiteSummary.Service;
|
||||
|
||||
@@ -35,14 +36,16 @@ public class RssFetch : IHostedService, IDisposable
|
||||
private readonly ILogger _logger;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly ConcurrentQueue<UserMessage> _queue;
|
||||
private readonly Hash _hash;
|
||||
|
||||
private static TimeSpan TimerPeriod => TimeSpan.FromSeconds(45);
|
||||
|
||||
public RssFetch(ILogger<RssFetch> logger, ConcurrentQueue<UserMessage> queue, IServiceScopeFactory scopeFactory)
|
||||
public RssFetch(ILogger<RssFetch> logger, ConcurrentQueue<UserMessage> queue, IServiceScopeFactory scopeFactory, Hash hash)
|
||||
{
|
||||
_scopeFactory = scopeFactory;
|
||||
_logger = logger;
|
||||
_queue = queue;
|
||||
_hash = hash;
|
||||
}
|
||||
|
||||
#region IHostedService
|
||||
@@ -132,7 +135,7 @@ public class RssFetch : IHostedService, IDisposable
|
||||
var postsImages = new Dictionary<Post, string>();
|
||||
foreach (var post in parsedFeed.Items)
|
||||
{
|
||||
feedPost = await dbContext.Posts.ByFeedAndUrl(post.Link, feed);
|
||||
feedPost = await dbContext.Posts.ByFeedAndUrlHash(_hash.GenerateHash(post.Link), feed);
|
||||
if (feedPost != null)
|
||||
{
|
||||
// skip. This post already exists.
|
||||
@@ -144,6 +147,7 @@ public class RssFetch : IHostedService, IDisposable
|
||||
feedPost.Title = post.Title;
|
||||
feedPost.Url = post.Link;
|
||||
feedPost.PostedAt = post.PublishingDate.GetValueOrDefault(DateTime.Now);
|
||||
feedPost.UrlHash = _hash.GenerateHash(feedPost.Url);
|
||||
|
||||
postsImages.Add(feedPost, await FetchImageUrl(post));
|
||||
newPosts.Add(feedPost);
|
||||
|
||||
Reference in New Issue
Block a user