This repository has been archived on 2023-06-30. You can view files and clone it, but cannot push or open issues or pull requests.
2chBackAPI/BufferControllers/BufferFill.cs

34 lines
1.2 KiB
C#
Raw Permalink Normal View History

2022-11-25 22:40:17 +10:00
using NeDvachAPI.DBControllers;
using NeDvachAPI.Models;
namespace NeDvachAPI.BufferControllers
2022-11-25 12:37:26 +10:00
{
public class BufferFill
{
public static bool FillBuffer(string board) //method to get buffer of information, which is being ran while API is started
{
2022-12-21 17:06:10 +10:00
List<Post> Previews = DBchat.ThreadsList(board);
APIThreadBuffer.WriteThreadPreviewsBuffer(Previews);
2023-01-30 11:02:30 +10:00
Console.WriteLine("Adding OP-posts to buffer");
2022-11-25 12:37:26 +10:00
2022-12-21 17:06:10 +10:00
for (int threadId = 1; threadId <= Previews.Count; threadId++)
2022-11-25 12:37:26 +10:00
{
2022-12-21 17:06:10 +10:00
APIThreadBuffer.AppendThreadsBuffer(DBchat.PostsList(board, threadId));
2022-11-25 12:37:26 +10:00
}
2023-01-30 11:02:30 +10:00
Console.WriteLine($@"Buffering threads {1} to {Previews.Count}.");
2022-12-21 17:06:10 +10:00
for (int preview = 0; preview < Previews.Count; preview++)
{
int targetLength = APIThreadBuffer.GetThreadLength(preview);
for (int lastofthree = targetLength- 2; lastofthree <= targetLength; lastofthree ++)
{
APIThreadBuffer.AppendToThreadPreviews(preview,APIThreadBuffer.GetSinglePost(preview,lastofthree));
}
}
2022-11-25 22:40:17 +10:00
return true;
2022-11-25 12:37:26 +10:00
}
}
}