Laravel Dusk works chronologically but doesn't with for loop - laravel

I have a select element and it has years as values such as '2019', '2018', '2017'...
If I try using them one after another like this it works:
$browser->select('year', '2019');
$browser->select('year', '2018');
$browser->select('year', '2017');
However, if I try to use it with a for loop, it doesn't work
$years = ['2019', '2018', '2017'];
foreach ($years as $year) {
Log::info($year);
$browser->select('year', $year);
}
// logs 2019 and then crashes
(Facebook\WebDriver\Exception\StaleElementReferenceException(code: 0): stale element reference: element is not attached to the page document
I tried using waitFor(), pause(5000) or even waitForReload() but nothing has changed (except waitForReload crashed because it waited for 5 seconds without change)

Related

Laravel tagging overhead leaving behind significantly large reference sets using redis

I am using Laravel 9 with the Redis cache driver. However, I have an issue where the internal standard_ref and forever_ref map that Laravel uses to manage tagged cache exceed more than 10MB.
This map consists of numerous keys, 95% of which have already expired/decayed and no longer exist; this map seems to grow in size and has a TTL of -1 (never expire).
Other than "not using tags", has anyone else encountered and overcome this? I found this in the slow log of Redis Enterprise, which led me to realize this is happening:
I checked the key/s via SCAN and can confirm it's a massive set of cache misses. It seems highly inefficient and expensive to constantly transmit 10MB back and forth to find one key within the map.
This quickly and efficiently removes expired keys from the SET data-type that laravel uses to manage tagged cache.
use Illuminate\Support\Facades\Cache;
function flushExpiredKeysFromSet(string $referenceKey) : void
{
/** #var \Illuminate\Cache\RedisStore $store */
$store = Cache::store()->getStore();
$lua = <<<LUA
local keys = redis.call('SMEMBERS', '%s')
local expired = {}
for i, key in ipairs(keys) do
local ttl = redis.call('ttl', key)
if ttl == -2 or ttl == -1 then
table.insert(expired, key)
end
end
if #expired > 0 then
redis.call('SREM', '%s', unpack(expired))
end
LUA;
$store->connection()->eval(sprintf($lua, $key, $key), 1);
}
To show the calls that this LUA script generates, from the sample above:
10:32:19.392 [0 lua] "SMEMBERS" "63c0176959499233797039:standard_ref{0}"
10:32:19.392 [0 lua] "ttl" "i-dont-expire-for-an-hour"
10:32:19.392 [0 lua] "ttl" "aa9465100adaf4d7d0a1d12c8e4a5b255364442d:i-have-expired{1}"
10:32:19.392 [0 lua] "SREM" "63c0176959499233797039:standard_ref{0}" "aa9465100adaf4d7d0a1d12c8e4a5b255364442d:i-have-expired{1}"
Using a custom cache driver that wraps the RedisTaggedCache class; when cache is added to a tag, I dispatch a job using the above PHP script only once within that period by utilizing a 24-hour cache lock.
Here is how I obtain the reference key that is later passed into the cleanup script.
public function dispatchTidyEvent(mixed $ttl)
{
$referenceKeyType = $ttl === null ? self::REFERENCE_KEY_FOREVER : self::REFERENCE_KEY_STANDARD;
$lock = Cache::lock('tidy:'.$referenceKeyType, 60 * 60 * 24);
// if we were able to get a lock, then dispatch the event
if ($lock->get()) {
foreach (explode('|', $this->tags->getNamespace()) as $segment) {
dispatch(new \App\Events\CacheTidyEvent($this->referenceKey($segment, $referenceKeyType)));
}
}
// otherwise, we'll just let the lock live out its life to prevent repeating this numerous times per day
return true;
}
Remembering that a "cache lock" is simply just a SET/GET and Laravel is responsible for many of those already on every request to manage it's tags, adding a lock to achieve this "once per day" concept only adds negligible overhead.

My Roblox Studio script is sometimes having errors.. idk why

So.. I've been coding to make a GUI show the quantity of currency of a player, the datastore API works perfectly but the local script doesn't (it's local because else it would just update it each time a player's currency gets updated and would be a mess being the opposite of what I want to)
and well... sometimes it loads the currency into the GUI but other times it just stays on the original text: "Label" instead of my current currency (4600)
here's the proof
What normally happens and should always happen
What sometimes happens and shouldn't happen:
here's the script, I've tried putting waits on the start but the original code is inside the while true do..
wait(game.Players.LocalPlayer:WaitForChild("Data")
wait(game.Players.LocalPlayer.Data:WaitForChild("Bells"))
while true do
script.Parent.TextLabel.Text = game.Players.LocalPlayer:WaitForChild("Data"):WaitForChild("Bells").Value
wait() --wait is for not making the loop break and stop the whole script
end
well.. if you want to see if data is really in the player, here's the script, it requires a API (DataStore2)
--[Animal Crossing Roblox Edition Data Store]--
--Bryan99354--
--Module not mine--
--Made with a AlvinBlox tutorial--
--·.·.*[Get Data Store, do not erase]*.·.·--
local DataStore2 = require(1936396537)
--[Default Values]--
local DefaultValue_Bells = 300
local DefaultValue_CustomClothes = 0
--[Data Store Functions]--
game.Players.PlayerAdded:Connect(function(player)
--[Data stores]--
local BellsDataStore = DataStore2("Bells",player)
local Data = Instance.new("Folder",player)
Data.Name = "Data"
Bells = Instance.new("IntValue",Data)
Bells.Name = "Bells"
local CustomClothesDataStore = DataStore2("CustomClothes",player)
local CustomClothes = Instance.new("IntValue",Data)
CustomClothes.Name = "CustomClothes"
local function CustomClothesUpdate(UpdatedValue)
CustomClothes.Value = CustomClothesDataStore:Get(UpdatedValue)
end
local function BellsUpdate(UpdatedValue)
Bells.Value = BellsDataStore:Get(UpdatedValue)
end
BellsUpdate(DefaultValue_Bells)
CustomClothesUpdate(DefaultValue_CustomClothes)
BellsDataStore:OnUpdate(BellsUpdate)
CustomClothesDataStore:OnUpdate(CustomClothesUpdate)
end)
--[test and reference functions]--
workspace.TestDevPointGiver.ClickDetector.MouseClick:Connect(function(player)
local BellsDataStore = DataStore2("Bells",player)
BellsDataStore:Increment(50,DefaultValue_Bells)
end)
workspace.TestDevCustomClothesGiver.ClickDetector.MouseClick:Connect(function(player)
local CustomClothesDataStore = DataStore2("CustomClothes",player)
CustomClothesDataStore:Increment(50,DefaultValue_CustomClothes)
end)
the code that creates "Data" and "Bells" is located in the comment: Data Stores
the only script that gets the issue is the short one with no reason :<
I hope that you can help me :3
#Night94 I tryed your script but it also failed sometimes
The syntax in your LocalScript is a little off with the waits. With that fixed, it works every time. Also, I would use an event handler instead of updating the value with a loop:
game.Players.LocalPlayer:WaitForChild("Data"):WaitForChild("Bells").Changed:Connect(function(value)
script.Parent.TextLabel.Text = value
end)

Code Not Working For Old Users After Website Migration

We have a website vehicle search page and over a week ago we migrated to a new hosting provider.
All old users who are revisting and some select users don't see any results on our search however when utilising dd on the collection of products it shows the correct count however the list of results are not part of the collection.
If we use incognito or flush our dns, chrome cache and local cache we can see the results properly.
I can provide the code pieces in question if required, however wondering if anyone has had this issue before.
Thanks
We have done the following;
Flushed the cache and cookie via code in the controller
localstorage refresh with jquery
localsession refresh with jquery
updated all versions on style sheets and javascript to refresh them
ran composer update to see if that helps
Cleared every inch of cache via laravel commands on the server ,application cache, views, routes, configs
new key
change cache clearance in htaccess
changed from Public to no-store in htaccess
The following 3 worked however not ideal as we can't utilise this on customers machines;
Flushed chrome cache via browser
Flushed dns via cmd line
Icognito
This is the part of code that retrieves and makes up the collection;
$products = $this->product->search($data, $page->id, 24, $type, $userlatLon);
This function is the following;
public function search($data, $pageId, $productsPerPage, $type, $userlatLon)
{
if($pageId == 1536){
unset($data['images']);
}
$sortArray = self::sortArray();
$avaiableFilters = self::avaliableFiltersArray();
$types = self::determineTypeFromGivenInt($type);
$select = 'products.url, products.id, products.registration_date, products.created_at as in_stock_date, products.location_code, products.type, products.special_order, products.price, products.sale_price, products.make, products.model,
products.derivative, products.mileage, products.live_until, products.model_year, products.year, products.times_viewed_in_the_last_week, products.transmission, products.tax_cost, products.fuel_type, our_title, our_description, i.our_src_440, f.term, f.first_payment, f.id as finance_id,
no_of_regular_payments, monthy_payments, final_payment, cash_price, cash_deposit, engine_size_formatted, total_deposit, amount_of_credit, total_charge_for_credit, total_amount_payable, products.plus_vat, products.attention_grabber,
apr, l.friendly_name as location_name, l.url as location_url, l.gmaps_url as gmaps, l.address_1, l.town, l.city, l.postcode, l.telephone, if(sale_price > 0 AND sale_price < (price - 100) , 1 , 0) as reduced';
!!!MORE QUERYING IS HERE!!!
if ($type == 4) {
$products = $products->has('pdfRecord')->groupBy('products.make', 'products.model')->paginate($productsPerPage, ['products.url']);
} else {
$products = $products->groupBy('products.id')->paginate($productsPerPage, ['products.url']);
}
return $products;
}
The expected results should be all products showing like a normal user sees.
However the collection returns 648 results but non of the results are part of the collection

Firebase android query performance issue

I have filtered query, which returns about 220 items with 8 fields each without child nodes. It's not tiny portion of data, but definately not the large one.
On the pic below the following happens:
Sec 25 - user click to load data, eventListener is created
Sec 31 - data is completely loaded from Firebase DB
1 min 47 - onDataChange is called and data is presented
I've seen some top process in debugger: FirebaseDatabaseWorker. Looks like it does some loaded data processing. But 1 minute with 30%CPU?? Is it possible to optimize?
Thanks!
final DatabaseReference artRef =
database.getReference("sales/"+store+"/articles");
Query query = artRef.orderByChild("familyId").equalTo(familyId);
query.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot child : snapshot.getChildren()) {
Article article = child.getValue(Article.class);
article.id = Integer.parseInt(child.getKey());
articles.add(article);
}
adapter.notifyDataSetChanged();
}
Disabling Instant Run in Android Studio made it from 1 minute to about 5 second to call onDataChange.

Sessions issue in laravel

From time to time, lets say 2 or 3 months, I get the following error in laravel in a browser session that is open for all those 2 or 3 months:
ErrorException
unserialize(): Error at offset 106 of 480 bytes
C:\inetpub\wwwroot\laravel\vendor\laravel\framework\src\Illuminate\Session\Store.php
protected function readFromHandler()
{
$data = $this->handler->read($this->getId());
return $data ? unserialize($data) : array();
}
Opening a hidden session in Chrome or just closing and opening the browser solves the problem.
Any idea what can it be?
It seems that your $data is not a properly serialize variable. you can dd the variable and check if it is properly serialize or a raw data.

Resources