Kroks
Kroks
CC#
Created by Kroks on 5/25/2024 in #help
How to use the same HttpClient instance with different session cookies / proxies?
No description
34 replies
CC#
Created by Kroks on 3/30/2024 in #help
EF-Core: Save one by one or bulk?
if (didAction) {
user.LastProcessed = DateTime.UtcNow;
await ctx.SaveChangesAsync(token);
}
if (didAction) {
user.LastProcessed = DateTime.UtcNow;
await ctx.SaveChangesAsync(token);
}
this code is part of a method that gets called approximately 1000 times, additionally this code is in a loop that runs approximately 10 times. Meaning this code gets executed 10000 times in one round (approximately). A lot of this will be executed in parallel (all Tasks returned by this method are in a Task.WhenAll(...)). Now I feel like CPU-Usage is too high sometimes and the issue is that sometimes the Database (postgres) even times out due to a lot of concurrency. To solve timeouts I made a custom context (threadsafe context) that has locks on all operations (savechanges etc.) to prevent concurrency on Database level (even though postgres supports it but times out if I use too much concurrency, so I may lose performance here already). Right now all of these method calls use the same context, i am not creating a new context for each method call I could also do the SaveChangesAsync after the Task.WhenAll, since the context is change tracking all the property changes (user.LastProcessed = ...), so a single save after all methods are done would work too. However I do not like this solution as it heavily relies on the fact that all methods DO exit at some point, if just one method call does never exit for whatever reason, then I lose data by not saving it. How would you approach this?
2 replies
CC#
Created by Kroks on 10/21/2023 in #help
❔ EFCore NPGSQL: Date exception
Unhandled exception. Npgsql.PostgresException (0x80004005): 42883: function date_part(unknown, bigint) does not exist When executing this piece of code:
var users = ctx.ScrapedUsers
.Where(user => user.Parents.Any(x => x.Id == target.Id) && user.StatusesCount > 0 && user.ScreenName != null
&& !ctx.Profiles
.Where(x => x.Id == Context.Profile.Id)
.Take(1)
.Any(x => x.ProcessedUsers.Any(x => x.Id == user.Id)) && user.LastProcessed.Year == 1970)
.OrderBy(user => user.LastProcessed)
.Take(processingCount - scrapedUsers.Count)
.ToList();
var users = ctx.ScrapedUsers
.Where(user => user.Parents.Any(x => x.Id == target.Id) && user.StatusesCount > 0 && user.ScreenName != null
&& !ctx.Profiles
.Where(x => x.Id == Context.Profile.Id)
.Take(1)
.Any(x => x.ProcessedUsers.Any(x => x.Id == user.Id)) && user.LastProcessed.Year == 1970)
.OrderBy(user => user.LastProcessed)
.Take(processingCount - scrapedUsers.Count)
.ToList();
in context I have thise
modelBuilder.Entity<ScrapedUser>()
.Property(su => su.LastProcessed)
.HasConversion<long>();
modelBuilder.Entity<ScrapedUser>()
.Property(su => su.LastProcessed)
.HasConversion<long>();
5 replies
CC#
Created by Kroks on 10/13/2023 in #help
❔ EFCore: Duplicate key violates unique constraint
No description
59 replies
CC#
Created by Kroks on 10/13/2023 in #help
❔ EFCore SQLITE Migrations on Server
I am developing with EFCore locally, however I copied the .db over to the server and on the server its filling the database with data. Now I have the issue that I need to change some table, so I was changing the corresponding model locally. Now my question, what would be the proper way to apply these changes to the .db that is on the server?
118 replies
CC#
Created by Kroks on 10/8/2023 in #help
❔ EFCore Sqlite Async: RAM and CPU Problem
So my code does the following: 30 Targets are being processed at once via async operations. Each second for each target I create 20 new Children of the target. So per second I have 20 * 30 new children. Each 20 children I call the "SaveAsync" method. However before I add a child to the database I want to ensure that the child does not exist yet, if it exists already I update its properties.
var existingUser = await ctx
.Children
.FirstOrDefaultAsync(x => x.RestID.Equals(scrapedUser.RestID));
var existingUser = await ctx
.Children
.FirstOrDefaultAsync(x => x.RestID.Equals(scrapedUser.RestID));
Im doing it with this code. I am assuming that EFCore loads all the children objects into memory, that leads to very high memory exposure, how can I prevent this? It should operate on Database level each time and not load all objects in RAM. It is important because I have millions on child object. Second issue is the CPU issue. Without doing the database actions, such as SaveAsync, FirstOrDefaultAsync the CPU is around 1% (normal for my Task), however with those methods after around 2mins I have a CPU over 90%.
455 replies
CC#
Created by Kroks on 10/7/2023 in #help
❔ EFCore: Unique Category Name
I have an issue with the entity "Category" that I have. Each "Target" Entity can have several categories, each category has a name and an Id. Target Entity has a List of Categories, however now when trying to add categories to an Entity there are duplicates. If I have two entities and add a category with the same name to both, there will be a dupe category (as the name exists two times and the name of Category entity should be unique)
36 replies
CC#
Created by Kroks on 9/14/2023 in #help
❔ MAUI Blazor: Hotreload not working
4 replies
CC#
Created by Kroks on 7/16/2023 in #help
❔ Blazor TypeConverter Exception
[TypeConverter(typeof(IListStringConverter))]
public List<string> AcceptedDomains { get; set; } = new List<string>()
{
"discord",
"linktr.ee",
};
}
[TypeConverter(typeof(IListStringConverter))]
public List<string> AcceptedDomains { get; set; } = new List<string>()
{
"discord",
"linktr.ee",
};
}
<textarea placeholder="Domains" @bind=DataService.Filter.AcceptedDomains></textarea>
<textarea placeholder="Domains" @bind=DataService.Filter.AcceptedDomains></textarea>
14 replies
CC#
Created by Kroks on 5/21/2023 in #help
✅ Blazor: Multiple Modals, different pages
Hello I have multiple modals that need to be in MainLayout.cs (otherwise they will not render as expected). Now I have also other pages, for example lets say Page1. Page1 can trigger a specific modal on button click. And it also need to take care of the actions that might happen in the Modal itself (e.g. Button Click). How would I structure this properly? Modal is a component:
<Modal @ref="newSocialMediaAccountModal">
<input placeholder="Identifier" />

<button>
Save
</button>
</Modal>
<Modal @ref="newSocialMediaAccountModal">
<input placeholder="Identifier" />

<button>
Save
</button>
</Modal>
needs to be in MainLayout but controlled by other pages.
29 replies
CC#
Created by Kroks on 5/18/2023 in #help
❔ .NET Maui Blazor: Render a Website inside the Application and get its cookies.
Hello, how can I have a Webview inside the Application itself? It cannot be an iframe since I need to load websites from another origin too and some websites will not load due to the response headers. Besides that I also need to scrape HttpOnly Cookies from that Website.
6 replies
CC#
Created by Kroks on 5/16/2023 in #help
❔ Blazor: Page loads only one time
Hello, I have an account list, each time I press on an account it loads a specific page (account overview). I set the currently selected Account in a Service, so that I can Initialize the Overview in the Overview page for that specific account. However "OnInitializedAsync" does not get triggered each time I navigate to the page, but only once. So that it works for the first account, but not for the second since it does not update. It needs to initialize some values for that specific account before it can render it.
8 replies
CC#
Created by Kroks on 5/9/2023 in #help
❔ .NET MAUI Blazor Windows Application does not start
Hi I wanted to deploy my application, I followed this tutorial: https://learn.microsoft.com/de-de/dotnet/maui/windows/deployment/overview However even after installing the certificate, I get this text when trying to install the msix: The publisher certificate of this app package could not be verified.Contact your system administrator or the app developer to get a new app package with verified certificates. The root certificate and all the instant signature certificates in the app package need to be verified (0x800B010A)
32 replies
CC#
Created by Kroks on 4/18/2023 in #help
❔ Is this usage of Tasks equivalent to Threads?
I have implemented this using Tasks. My goal is to load the sessions in parallel since they are not dependent on each other. I could have used threads, but I came up with this solution instead. See how I do not await CreateSessionAsync, I await all tasks at the end. I could have also used Threads to split the session loading. Question is now, is there a major difference?
185 replies
CC#
Created by Kroks on 4/11/2023 in #help
✅ How to install a callback for an awaited item when using Task.WhenAll
Hello I am using Task.WhenAll on a List of Tasks. However if a task fails I want to immediately call another function on the task (for retrying it and handling other things). How can I do that? I want a solution with good performance.
19 replies
CC#
Created by Kroks on 3/24/2023 in #help
❔ Structure of heap-allocated Object in C# (Method-Table especially).
Asking for the structure of a .NET object in memory. I know that it starts with the address of the method table, after that you have all the field vlaues of the object. However I would like to know more about the method table especially. The information I found online seem to be incomplete or contradict each other.
8 replies
CC#
Created by Kroks on 3/7/2023 in #help
❔ How to control content security policy in MAUI Blazor webview?
^
2 replies