Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
4e1400ce
Commit
4e1400ce
authored
6 years ago
by
Akihiko Odaki
Committed by
Eugen Rochko
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Cache media only when storage can be freed (#7547)
parent
bcbb6aa4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/javascript/mastodon/service_worker/entry.js
+2
-2
2 additions, 2 deletions
app/javascript/mastodon/service_worker/entry.js
app/javascript/mastodon/storage/modifier.js
+6
-4
6 additions, 4 deletions
app/javascript/mastodon/storage/modifier.js
with
8 additions
and
6 deletions
app/javascript/mastodon/service_worker/entry.js
+
2
−
2
View file @
4e1400ce
import
{
freeStorage
}
from
'
../storage/modifier
'
;
import
{
freeStorage
,
storageFreeable
}
from
'
../storage/modifier
'
;
import
'
./web_push_notifications
'
;
function
openSystemCache
()
{
...
...
@@ -49,7 +49,7 @@ self.addEventListener('fetch', function(event) {
return
response
;
}));
}
else
if
(
process
.
env
.
CDN_HOST
?
url
.
host
===
process
.
env
.
CDN_HOST
:
url
.
pathname
.
startsWith
(
'
/system/
'
))
{
}
else
if
(
storageFreeable
&&
process
.
env
.
CDN_HOST
?
url
.
host
===
process
.
env
.
CDN_HOST
:
url
.
pathname
.
startsWith
(
'
/system/
'
))
{
event
.
respondWith
(
openSystemCache
().
then
(
cache
=>
{
return
cache
.
match
(
event
.
request
.
url
).
then
(
cached
=>
{
if
(
cached
===
undefined
)
{
...
...
This diff is collapsed.
Click to expand it.
app/javascript/mastodon/storage/modifier.js
+
6
−
4
View file @
4e1400ce
...
...
@@ -4,6 +4,11 @@ const accountAssetKeys = ['avatar', 'avatar_static', 'header', 'header_static'];
const
storageMargin
=
8388608
;
const
storeLimit
=
1024
;
// navigator.storage is not present on:
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.100 Safari/537.36 Edge/16.16299
// estimate method is not present on Chrome 57.0.2987.98 on Linux.
export
const
storageFreeable
=
'
storage
'
in
navigator
&&
'
estimate
'
in
navigator
.
storage
;
function
openCache
()
{
// ServiceWorker and Cache API is not available on iOS 11
// https://webkit.org/status/#specification-service-workers
...
...
@@ -182,10 +187,7 @@ export function putStatuses(records) {
}
export
function
freeStorage
()
{
// navigator.storage is not present on:
// Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.100 Safari/537.36 Edge/16.16299
// estimate method is not present on Chrome 57.0.2987.98 on Linux.
return
'
storage
'
in
navigator
&&
'
estimate
'
in
navigator
.
storage
&&
navigator
.
storage
.
estimate
().
then
(({
quota
,
usage
})
=>
{
return
storageFreeable
&&
navigator
.
storage
.
estimate
().
then
(({
quota
,
usage
})
=>
{
if
(
usage
+
storageMargin
<
quota
)
{
return
null
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment