Cache query result

Category Image 101

I come across this problem every so often and end up having to do work arounds when I would prefer to keep it in the database. I have a query where the data in the query updates frequently so the query won't stay in the cache but I don't need the query to be accurate. I was trying to avoid adding an extra step of storing the data in a temp table and having to update it on a timer.

Does anyone know of a way to get MariaDB or MySQL to Keep the result set for a period of an hour or so before actually running the query again, I have an example of a query below which takes between 4.8-6 seconds to run and the wait is too long and also is needless work for the server, It can just do the query once and get the 4 numbers - then all subsequent requests just return the 4 numbers and every 20 minutes or 1 hour the 4 numbers get updated.

Is there a built in funtion for this or is the only solution to make your own table? I could end up with many of these and I don't want to end up with 100's

SELECT
    SUM(CASE WHEN p.id IS NULL AND f.loc = 1 THEN 1 ELSE 0 END)/250 to_print
    , SUM(CASE WHEN p.id IS NULL AND f.loc NOT IN(1,2,8) THEN 1 ELSE 0 END)/250 to_print_out
    , SUM(CASE WHEN p.id IS NOT NULL AND p.print_date BETWEEN '2020-01-09 14:00:00' AND '2020-01-16 14:00:00' THEN 1 ELSE 0 END)/250 printed_tw
    , SUM(CASE WHEN p.id IS NOT NULL THEN 1 ELSE 0 END)/250 printed
    FROM typist t
    LEFT JOIN printing p ON t.typed_id = p.print_id AND p.type = 4
    LEFT JOIN files f ON t.file_id = f.file_id
    WHERE
    t.type = 1
    AND f.file_id IS NOT NULL
    AND NOT EXISTS(SELECT DISTINCT l.id FROM letters l WHERE l.deleted = 1 AND t.letter_id = l.id)

This is the EXPLAIN for the query

"1" "PRIMARY"   "t" "ref"   "file_id,letter_type,print_stat"    "print_stat"    "2" "const" "134243"    "Using where; Using index"
"1" "PRIMARY"   "f" "eq_ref"    "PRIMARY"   "PRIMARY"   "3" "sys.t.file_id" "1" ""
"1" "PRIMARY"   "p" "ref"   "id,type"   "particle_id"   "8" "sys.t.typed_id"    "1" "Using where"
"2" "MATERIALIZED"  "l" "ref"   "PRIMARY,deleted,deleted_file_id"   "deleted"   "1" "const" "4741"  "Using index"

I have already had numerous variations to try optimising this and the above is the best I have got so far. t has around 200,000 rows, l has around 300,000, f has about 130,000, p has around 300,000 but will bloat well over 1,000,000 in time.

How to Create a Simple and Efficient PHP Cache

Featured Imgs 23
When working on PHP websites made from scratch and without a framework, speed can often be an issue. Caching is extremely useful in order to speed up PHP webpages. In this article, I’ll show you how to make a simple PHP caching system for your web pages. What is Page Caching? Page caching is a […]

Re-creating the ‘His Dark Materials’ Logo in CSS

Featured Imgs 23

The text logo has a slash cut through the text. You set two copies on top of one another, cropping both of them with the clip-path property.

What's interesting to me is how many cool design effects require multiple copies of an element to do something cool. To get the extra copy, at least with text, we can sometimes use a pseudo-element. For more elaborate content, there is an element() function in CSS, but it's limited to a prefixed property in Firefox. Still, it enables awesome stuff, like making a mini-map of long content.

You can style it differently with a pseudo-element, which was useful here. Might be cool to see a way to clone elements on a page and apply styling all through CSS... someday.

See the Pen
His Dark Materials TV series logo with CSS
by Michelle Barker (@michellebarker)
on CodePen.

Direct Link to ArticlePermalink

The post Re-creating the ‘His Dark Materials’ Logo in CSS appeared first on CSS-Tricks.

Water.css

Featured Imgs 23

It's notable that Water.css was the #1 clicked thing from Louis Lazaris' Web Tools Weekly in 2019. It's from a 13-year old developer named Felix!

It's just a little bit of CSS you apply to class-free semantic HTML to give it nice basic responsive styles — the perfect kind of thing for a Pen when you are just tossing some markup together and want it to look nice.

Direct Link to ArticlePermalink

The post Water.css appeared first on CSS-Tricks.

what3words Launches Voice API Powered by Speechmatics

Featured Imgs 23

what3words, an innovative location solution provider, just announced its new Voice API, powered by Speechmatics. what3words has divided the world into three-meter squares, with each square represented by a unique set of three individual words (e.g. the three word identifier for the what3words headquarters is filled-count-soap). By using a three-word identifier, duplicative and mispronounced street addresses are eliminated.

Is it better to use ems/rems than px for font-size?

Category Image 052

The answer used to be absolutely yes because, if you used px units, you prevented the text from being resized by the user at all.

But browser zoom is the default method for making everything bigger (including text) these days and it works great even if you use px.

But... Kathleen McMahon really digs into this and finds that it's still worth setting all your type (both font-size and line-height) in relative units because:

  1. setting type in px prevents browser settings from making font size adjustments (which some people definitely use) and
  2. setting type in relative units maintains greater design fidelity as users use browser zoom (which a lot of people definitely use).

Direct Link to ArticlePermalink

The post Is it better to use ems/rems than px for font-size? appeared first on CSS-Tricks.

How secure is WordPress as compared to other CMS?

Featured Imgs 23

The content management systems (CMS) like WordPress have made the creation and management of websites and blogs very easier. WordPress, Drupal, and Joomla are currently the top content management systems out there. These systems provide some tools to help you build websites. These tools are different for every platform, having their pros and cons. But […]

The post How secure is WordPress as compared to other CMS? appeared first on designrfix.com.

Simple WooCommerce Tips to Make Your Store Even Better

Featured Imgs 26

These days starting your own online store doesn’t have to be just a dream. Thanks to WordPress anyone can build an online store with WooCommerce. It’s quick, fairly easy and you can set up a professional looking website to sell your products without spending a ton of money. What’s more, with these simple WooCommerce tips […]

The post Simple WooCommerce Tips to Make Your Store Even Better appeared first on WPExplorer.

Is “is” Useful?

Category Image 052

God I'm funny.

Anytime we have fairly repetitive selectors that have a common parent, it's probably a place we can use the :is() pseudo-selector.

Holger Bartel demonstrates like this:

section section h1, section article h1, section aside h1, section nav h1,
article section h1, article article h1, article aside h1, article nav h1,
aside section h1, aside article h1, aside aside h1, aside nav h1,
nav section h1, nav article h1, nav aside h1, nav nav h1 {
  font-size: 20px;
}

Becomes:

:is(section, article, aside, nav)
:is(section, article, aside, nav) h1 {
  font-size: 20px;
}

Adam Argyle demonstrated like this:

MDN has an extra dramatic one:

ol ol ul,     ol ul ul,     ol menu ul,     ol dir ul,
ol ol menu,   ol ul menu,   ol menu menu,   ol dir menu,
ol ol dir,    ol ul dir,    ol menu dir,    ol dir dir,
ul ol ul,     ul ul ul,     ul menu ul,     ul dir ul,
ul ol menu,   ul ul menu,   ul menu menu,   ul dir menu,
ul ol dir,    ul ul dir,    ul menu dir,    ul dir dir,
menu ol ul,   menu ul ul,   menu menu ul,   menu dir ul,
menu ol menu, menu ul menu, menu menu menu, menu dir menu,
menu ol dir,  menu ul dir,  menu menu dir,  menu dir dir,
dir ol ul,    dir ul ul,    dir menu ul,    dir dir ul,
dir ol menu,  dir ul menu,  dir menu menu,  dir dir menu,
dir ol dir,   dir ul dir,   dir menu dir,   dir dir dir {
  list-style-type: square;
}
:is(ol, ul, menu, dir) :is(ol, ul, menu, dir) ul,
:is(ol, ul, menu, dir) :is(ol, ul, menu, dir) menu,
:is(ol, ul, menu, dir) :is(ol, ul, menu, dir) dir {
  list-style-type: square;
}

It's less code and easier to reason.

Kezz Bracey notes that pairing it with :not() can be nice as well:

:not(article, section, aside) :is(h1, h2, h3, h4, h5, h6) {
  font-weight: 400;
}

Browser support is just starting to get there and polyfilling is hard, so we aren't at day-to-day no-brainer use levels quite yet. I'd bet it's not too far away.

The post Is “is” Useful? appeared first on CSS-Tricks.