postgresql – Postgres – How to prevent locking when parent table is updated whenever an insert/delete occurs in child table

I have a simple use case wherein I update the parent table when a row is inserted/deleted in the child table.

Suppose we have a Products table and Items table and ProductId is the foreign key in the Items table.

Whenever an item is inserted or deleted in the Items table, an update is made in the Products table corresponding to the item. An update is simply a query like:

UPDATE "Products" SET "PropertyX" = $1, "UpdatedAt" = $2 WHERE "Id" = $3

Problem:

If the items inserted/deleted in the items table correspond to the same product in the products table then the database load increases considerably causing timeouts even for 3K reqs/min due to Lock:transactionid waits.

I tested this on Aurora Postgres (with 4 CPUs, 16G Ram) and this happens even if the number of rows in the Items table is in the thousands and the number of rows in the Products table is in the hundreds. I used .net core with entity framework.

How to identify parent term for child term in Sharepoint Online Search query using user profile property tied to a term store?

I am new to the Sharepoint world and Sharepoint Online Search. As a beginner, I am attempting to learn and achieve the following task.
I have a Geography term store that has

Global (Root)

Region1
    United States
    Canada
Region2
    Country3
    Country4

and so forth…

Content in Sharepoint could be tagged with values from this term store at any level. (Global, region or country)

Users in the system have user profiles and there is a custom property called “Country” that derives values from this Term store. Only countries (the leaf nodes) get assigned on this property as users select the country in their profiles.

When a user searches, I want to boost the results that are tagged with the user’s country OR with the corresponding Region OR the root.
I tried the XRANK query to achieve this.

{searchTerms} XRANK(cb=1.00 stdb=1.00) tags:{User.Country}

This works, but only when the content’s tag has a Country value. But I want to identify the parent of the country (the region and the root) and include it as the matching condition to boost. That is, if I am in Country3, both Region2 and the root are relevant to me as well. What properties should I create to capture the geography parents on the user profile and how? How should I modify the XRANK query? Appreciate your answers!

c# – How to use single child Unity container for OWIN middleware and WebAPI

I am using OWIN to self host WebAPI service. There is Unity to serve as IoC container. Within several OWIN middlewares (e.g. authorization layer) as well as in WebAPI I need to access unity container to resolve my dependencies. There should be single child container per each request so that there is for example single DB context which is used several times during the request and it is disposed at the end of request along with unity container. For WebAPI I would like to use same container as for previous middlewares. However, default UnityHierarchicalDependencyResolver creates its own child container from given parent per each request. So that I had to write my own infrastructure to force WebAPI to use existing child container. Please review the following code snippets. I would be happy for any kind of feedback since this is quite critical part of my application.

Here is my app configuration method:

public static void Configure(IAppBuilder app, IUnityContainer container)
{
    //register middleware that creates child container for each request
    app.UseUnityContainer(container);

    //register other middlewares ...
    
    //create httpconfig
    var config = new HttpConfiguration
    {
        DependencyResolver = container.Resolve<OwinUnityDependencyResolver>()
    };

    //...

    config.MessageHandlers.Insert(0, container.Resolve<OwinDependencyScopeHandler>());

    app.UseWebApi(config);
}

This is UseUnityContainer extension method that is responsible for creating and disposing child containers:

public static void UseUnityContainer(this IAppBuilder app, IUnityContainer container)
{
    app.Use<UnityMiddleware>(container);
}

private class UnityMiddleware : OwinMiddleware
{
    private readonly IUnityContainer _parent;

    public UnityMiddleware(OwinMiddleware next, IUnityContainer parent) : base(next)
    {
        _parent = parent;
    }

    public override async Task Invoke(IOwinContext context)
    {
        using (var child = _parent.CreateChildContainer())
        {
            context.SetUnityContainer(child);
            await Next.Invoke(context);
        }
    }
}

To access and store container within the OWIN context there are following extension methods:

public static class UnityOwinContextExtensions
{
    private const string UnityContainerKey = "OwinUnityContainer";

    public static IUnityContainer GetUnityContainer(this IOwinContext context)
    {
        return context.Get<IUnityContainer>(UnityContainerKey);
    }

    public static void SetUnityContainer(this IOwinContext context, IUnityContainer container)
    {
        context.Set(UnityContainerKey, container);
    }
}

OwinUnityDependencyResolver class used in HttpConfiguration:

public class OwinUnityDependencyResolver : IDependencyResolver
{
    private static readonly IDependencyScope NullScope = new NullDependencyScope();

    private readonly IUnityContainer _parent;

    public OwinUnityDependencyResolver(IUnityContainer parent)
    {
        _parent = parent;
    }

    public void Dispose()
    {
        //parent container is disposed in SureStowWebApiService
    }

    public object GetService(Type serviceType)
    {
        try
        {
            return _parent.Resolve(serviceType);
        }
        catch (ResolutionFailedException)
        {
            return null;
        }
    }

    public IEnumerable<object> GetServices(Type serviceType)
    {
        try
        {
            return _parent.ResolveAll(serviceType);
        }
        catch (ResolutionFailedException)
        {
            return null;
        }
    }

    public IDependencyScope BeginScope()
    {
        //BeginScope should not be called as there should be already scope registered by OwinDependencyScopeHandler
        return NullScope;
    }

    private class NullDependencyScope : IDependencyScope
    {
        public void Dispose()
        {
        }

        public object GetService(Type serviceType) => null;

        public IEnumerable<object> GetServices(Type serviceType) => null;
    }
}

OwinDependencyScopeHandler class that is used to retrieve existing child container from OWIN context and create new dependency scope out of it. This handler is registered in HttpConfiguration.

public class OwinDependencyScopeHandler : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        var context = request.GetOwinContext();
        var scope = new OwinUnityDependencyScope(context);

        //this prevents HttpRequestMessageExtensions.GetDependencyScope to initialize scope from dependency resolver
        request.Properties(HttpPropertyKeys.DependencyScope) = scope;

        return base.SendAsync(request, cancellationToken);
    }
    
    private class OwinUnityDependencyScope : IDependencyScope
    {
        private readonly IUnityContainer _container;

        public OwinUnityDependencyScope(IOwinContext owinContext)
        {
            _container = owinContext.GetUnityContainer(); //this is child container created by UnityMiddleware
        }
        
        public void Dispose()
        {
            //_container should be disposed by UnityMiddleware
        }

        public object GetService(Type serviceType) => _container.Resolve(serviceType);

        public IEnumerable<object> GetServices(Type serviceType) => _container.ResolveAll(serviceType);
    }
}

mysql – Child query count, repeated results or incomplete results

I am making a query that tells me how many times an id from table B appears in table A, and when it appears, count their respective fields

this is the expected result, but obviously this result does not help me to show it in the front
enter image description here

so I am trying to do it with sub querys

enter image description here

and this

enter image description here

19 RECUPERADOS
10 A-AUTORIZAR

If you could guide me or give me a clue where my mistake is, that would be very nice

overrides – Overide a class doesn’t work for his child?

I want to override this class : ‘MagentoCheckoutBlockCartItemRenderer’
This class has a child like : ‘MagentoConfigurableProductBlockCartItemRenderer’

So i use <preference for="MagentoCheckoutBlockCartItemRenderer" type="CustomCheckoutBlockCartItemRenderer" />

It’s works only when i use the parent class ( CartItemRenderer ). but when i instantiate the child i can’t use my custom function.
Is there something else to do ?
I have to override all the child class ?

8 – Trying to configure parent link and child links in menu

I’m trying to create a submenu in the same way shown in the screenshotConfiguration(parent) and Store, Products, Payment, Orders as the child links

module.links.menu.yml:

custom_forms_entity_export_csv.export:
  title: 'Export'
  description: 'Export Menu'
  route_name: custom_forms_entity_export_csv.export
  parent: commerce.admin_commerce

custom_forms_entity_export_csv.export_sales_form:
  title: 'Export Sales'
  description: 'Export Sales to a CSV file.'
  route_name: custom_forms_entity_export_csv.export_sales_form
  parent: commerce.admin_commerce

custom_forms_entity_export_csv.export_menu_form:
  title: 'Export Menu'
  description: 'Export Menu to a CSV file.'
  route_name: custom_forms_entity_export_csv.export_menu_form
  parent: custom_forms_entity_export_csv.export

module.routing.yml

custom_forms_entity_export_csv.export:
  path: '/admin/commerce/export'
  defaults:
    _controller: 'DrupalsystemControllerSystemController::systemAdminMenuBlockPage'
    _title: 'Commerce'
  requirements:
    _permission: 'access commerce administration pages'

custom_forms_entity_export_csv.export_sales_form:
  path: '/admin/commerce/export/sales'
  defaults:
    _title: 'Sales'
    _form: Drupalcustom_forms_entity_export_csvFormSalesExportCsvForm
  requirements:
    _permission: 'use custom export csv'

custom_forms_entity_export_csv.export_menu_form:
  path: '/admin/commerce/export/menu'
  defaults:
    _title: 'Menu'
    _form: Drupalcustom_forms_entity_export_csvFormMenuExportCsvForm
  requirements:
    _permission: 'use custom export csv'

module.links.task.yml

custom_forms_entity_export_csv.export_sales_form:
  title: 'Download Sales'
  base_route: custom_forms_entity_export_csv.export
  route_name: custom_forms_entity_export_csv.export_sales_form
  weight: 100

custom_forms_entity_export_csv.export_menu_form:
  title: 'Download Menu'
  base_route: custom_forms_entity_export_csv.export
  route_name: custom_forms_entity_export_csv.export_menu_form
  weight: 100

But all I end up with is all three links, Export, Export Sales, and Export Menu as children under the same Commerce menu, like shown here:
All three export links are at the same level

What I want is for Export to have an arrow on the right to expand a submenu containing Export Sales and Export Menu.

What should be the schema of the database if the parent table is being referenced in more than one child table?

I have three entities in my database: Category, SubCategory, and Product. Now the thing is SubCategory is dependent on Category, whereas Product can be dependent on SubCategory or directly either on Category.
How should I design the database for such a situation?

As of now, I have created these tables as below:

Category:

  • CategoryId
  • CategoryName
  • HasSubCategory

SubCategory:

  • SubCategoryId
  • CategoryId
  • SubCategoryName

Product:

  • ProductId
  • CategoryId
  • SubCategoryId
  • ProductName

Now, while creating a Product, if the selected Category’s HasSubCategory is true then SubCategory would be selected by the user. Now consider a situation that the user selects a Category whose HasSubCategory is true, and based on the selected Category, SubCategories will be loaded and after selecting a SubCategory, the user submits the Product record. Now, what if the user modifies the SubCategory record which was selected in the Product, and changes its dependent Category. In this case, I need to update the Product record as well and change its Category as per the new Category selected in the SubCategory record.

Is there any better approach to handle such a situation or I shall manage like this only?

block editor – How to override the font size values for Gutenburgs Typography options in a child theme?

I see within WordPress 5.5.3, Gutenberg provides the following typography options when managing text…

enter image description here

Is there an action I can add to my child theme that allows me to override the default font sizes set on these first 6 options?

If so, how do we set it up?

In child theme, add CPT to custom taxonomy registered in parent theme

I’m using Divi with a child theme. Divi (parent theme) has a CPT called project and two custom taxonomies, project_category and project_tag.

In my child theme I created a CPT called external_project. I want this newly created CPT to share the same taxonomies that the built-in Projects post type has. When registering this CPT I added 'taxonomies' => array( 'project_category', 'project_tag' ), to the args. But they’re not showing up. So I’m assuming I also need to add this newly created CPT to the array of object types the custom taxonomy is associated with.

I tried the following. I didn’t think it would work but I just wanted to try something, and of course it didn’t work. So don’t judge me too hard for it lol

function add_cpt_to_project_tax() {
    register_taxonomy('project_category', array('project', 'external_project'));
    register_taxonomy('project_tag', array('project', 'external_project'));
}
add_action('after_setup_theme', 'add_cpt_to_project_tax');

So my question is…Does anyone know of a hook or function I can create that will add the newly created CPT in my child theme, to the custom taxonomy registered in the parent theme? I’m having a tough time finding any examples online or anything in the codex that will help with my specific scenario. Any help would be greatly appreciated.

custom post types – Remove Parent term slug from URL when Child selected if not keep Parent term slug in URL

i have parent-child relation in taxonomy(city) terms, now i want to keep parent term slug in URL only if there is no child attached with a post like this is my URL structure

example.com/state/city/store-number/store

now in city taxonomy, i have parent term Chicago and then child term Villa park, and URL structure is

example.com/illinois/chicago/villa-park/8716508/anca-micoara-ea/

now in the above URL both parent (Chicago) and child term (Villa park) attached with a post please check the screenshot here https://prnt.sc/vb3n13
so for this, URL structure is fine but i want when i select only child term for the post i want URL structure something like this

example.com/illinois//villa-park/8716508/anca-micoara-ea/

please check the screenshot here https://prnt.sc/vb3orl
like i want to remove parent term from URL when only child selected, not sure how i will do that? am using the permalink manager lite plugin but i don’t see any option for this