page speed – Why does the Lighthouse API show occasional spikes in total blocking time?

I am using the Lighthouse API to get page load metrics for my site. I’m getting some huge outliers for my Total Blocking Time (TBT) metrics.

Since the results are a little different with each request, I’m taking the average of 5, so I’m making 5 requests per URL I’m testing.

All other metrics differ slightly with each request, except for TBT. Usually it ranges from 0 to about 80, but then sometimes it comes back appx 800. See screenshot below, where TBT is third column of data, and the rows are 5 requests for one URL. The last row is the average.

enter image description here

console application – Como fazer fetch no react native com api de um site php no infinityfree

Saudaçoes pessoal, tenho um problema com o meu app, estava usando fetch no localhost com php e tudo dava certo, quando fiz a build do apk e passei todos os arquivos pra o servidor online, troquei o link que usava no fetch pra o link do meu site, agora me retorna um erro algo como: unexpected json parse token ‘<‘, alguem sabe o que se passa?

fetch();

users – WordPress API for search

I have a search form for users on my website. I have a custom field called ‘location’ which is a country dropdown. If I type in a user’s name and select a country from the dropdown I see this in the url when I submit:

https://example.com/?s=bob&location=germany

If I search for bob in France I get no results because bob has set his location to Germany.
If I just search for bob I will find him.
if I just search in Germany I will find him.
If I search for Bob in Germany I will find him.

So, I want the same thing using the API.

If I send a GET request to

 https://example.com/wp-json/wp/v2/users?search=bob

I get a result as I would want. But if I try just by location or name and location, I just get ALL the users back.

So, I tried:

https://example.com/wp-json/wp/v2/users?location=germany

This gave me all the users and this also gave me all the users

https://example.com/wp-json/wp/v2/users?search=bob&location=germany

Form API – form ID value changing which breaks the action# link

I have a custom module creating a form. As the form is a bit down the page, I have added an anchor to the submit so the user sees the results without the need to scroll down

  public function getFormId() {
    return 'form_name_form';
  }

  public function buildForm(array $form, FormStateInterface $form_state, $entity_id = NULL) {
    $form('#action') = '#form_name_form';
    //.. rest of form removed for clarity
  }

This works and then it does not… I can see why:

<form class="form_name_form" data-drupal-selector="form_name_form" action="#form_name_form" method="post" id="form_name_form" accept-charset="UTF-8">

Becomes

<form class="form_name_form" data-drupal-selector="form_name_form-2" action="#form_name_form" method="post" id="form_name_form--2" accept-charset="UTF-8">

But I am not sure how to stop the addition of ‘–2’ to the ID?
Or set $form(‘#action’) = ‘#form_name_form’; to the actual generated form id?

page speed – Lighthouse API reports occasional spikes in total blocking time

I am using the Lighthouse API to get page load metrics for my site. I’m getting some huge outliers for my Total Blocking Time (TBT) metrics.

Since the results are a little different with each request, I’m taking the average of 5, so I’m making 5 requests per URL I’m testing.

All other metrics differ slightly with each request, except for TBT. Usually it ranges from 0 to about 80, but then sometimes it comes back appx 800. See screenshot below, where TBT is third column of data, and the rows are 5 requests for one URL. The last row is the average.

enter image description here

$this.refs, this.$router, this.$route access with Composition API VueJS

Can you please tell me how to access $this.refs, this.$router, this.$route in Composition API setup function? There are solutions mentioned with context.$root but $root is not available with context anymore. Please help.

page speed – Lighthouse API – Total Blocking Time

I am using the Lighthouse API to get page load metrics for my site. I’m getting some huge outliers for my Total Blocking Time metrics.

Since the results are a little different with each request, I’m taking the average of 5, so I’m making 5 requests per URL I’m testing.

All other metrics differ slightly with each request, except for TBT. Usually it ranges from 0 to about 80, but then sometimes it comes back appx 800. See screenshot below, where TBT is third column of data, and the rows are 5 requests for one URL. The last row is the average.

enter image description here

Accessing data from android.view.View#getAnimationMatrix in api level below 29

I am trying to animate recyclerview divider decorations as the actual view animates.

override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
        val childCount = parent.childCount
        for (i in 0 until childCount - 1) {
            val child = parent.getChildAt(i)
            val childAdapterPosition = parent.getChildAdapterPosition(child)
                    .let { if (it == RecyclerView.NO_POSITION) return else it }
            val type = parent.adapter?.getItemViewType(childAdapterPosition)
            val drawable = itemViewTypesMap(type)?.drawable ?: continue
            val margin = itemViewTypesMap(type)?.margin?.toInt() ?: 0
            val params = child.layoutParams as RecyclerView.LayoutParams
            val childLeftOffset = child.paddingLeft + params.leftMargin
            val childRightOffset = child.paddingRight + params.rightMargin
            val dividerLeft = if (parent.clipToPadding) 0 + childLeftOffset else parent.paddingLeft + childLeftOffset
            val dividerRight = if (parent.clipToPadding) parent.width - childRightOffset else parent.width - parent.paddingRight - childRightOffset
            val dividerTop = child.bottom + params.bottomMargin + child.translationY.roundToInt()
            val offset = child.animationMatrix?.values()?.get(5)?.toInt() ?: 0
            val dividerBottom = dividerTop + drawable.intrinsicHeight
            drawable.setBounds(dividerLeft + margin, dividerTop + offset, dividerRight - margin, dividerBottom + offset)
            drawable.draw(canvas)
        }
    }

The code above is working great, but IDE complains about child.animationMatrix that is added in api 29. Using child.matrix does not work since it contains only 0.0 values. Also using child.getTranslationY always returns 0.0.

It should help that we use this kind of animations:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="@android:anim/decelerate_interpolator">
    <translate
        android:duration="400"
        android:fromXDelta="0%"
        android:fromYDelta="100%"
        android:toXDelta="0%"
        android:toYDelta="0%" />
</set>

and loading them by:

viewHolder.itemView.startAnimation(AnimationUtils.loadAnimation(viewHolder.itemView.context, R.anim.down_from_top))

rest – One API endpoint for each frontend “need”

How many other clients to this API will there be?

If this is the only client, why not. Its use case is tailored to just this usage, just this representation. Assuming your client isn’t trying to be smart and load/cache the object across end points, this can be a very efficient way of writing an API. When your client changes its easy to cleanup old code paths without worrying that somewhere else is also using the end-point.

If you have more than one client, this strategy starts to become problematic. One size never really fits anyone, and a bespoke fit even less so.

You could possibly provide tailor made api-endpoints for both clients, but now you run into the fact that some end-points are duplicates (to keep the one to one mapping), and others have such small differences you might have to read the code very deeply to spot it. But this strategy quickly becomes more difficult the more clients are added, and the business will quite rightly ask what is the difference between supporting 1, 2, or 50 clients? <Insert Name of a Titan Software Company> does it!

Once you get to your second client you really should be looking at refactoring out the commonalities. There may still be some bespoke api end-points for just this or just that client and use case, but the API should be moving toward orthogonal and composable calls. This API will oversupply detail for some views, and other views need to combine data from several API end-points, but those API’s will be generally useful to most clients, and much fewer in number simplifying support and maintenance.

Alternately give up on REST and transition to a stateful communication model using websockets – a complicated solution that has pay offs in some scenarios. I don’t recommend it for you situation as it appears though.

magento2 – REST API: Consumer is not authorized to access %resources

I’m in the middle of finishing a Magento 2 store for a client. The last I had on my to-do list, was connect Magento to their accounting software through the REST API.

However, apparently there’s some serious issue when it comes to the REST API in the Magento installation. No matter what I do I’m always given a “Consumer is not authorized to access %resources” error, such as:

{
    "message": "Consumer is not authorized to access %resources",
    "parameters": {
        "resources": "Magento_Sales::sales"
    }
}

POSTMAN Settings:enter image description here

I’m using an Access Token created through Admin > System > Integrations. The created Integration has resource access set to ALL.

System:

  • CentOS 7
  • WHM/cPanel
  • PHP 7.3.27
  • PHP Handler SuPHP
  • Magento 2.4.1
  • Webserver: Apache (port 8080)
  • Cache: Varnish (port 80)
  • SSL: Nginx as reverse proxy for SSL (port 443)

Things I’ve tried based on similar questions:

  • Change PHP handler from CGI to SuPHP (source)
  • Enable individual API resource access instead of setting to ‘ALL’ (source)
  • Tested without Varnish between client and server
  • Tested without Nginx proxy between client and server

I really can’t seem to figure out what I’m doing wrong here. Does anybody have an idea what might be causing this? An option would be to do a fresh installation, but that’d be my very last option as I’ve been working on this Magento environment (theme, thouuuusands of products, …) for many months.