Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drill down to see disk usage by module and/or user #625

Open
Fragonite opened this issue Aug 20, 2024 · 0 comments
Open

Drill down to see disk usage by module and/or user #625

Fragonite opened this issue Aug 20, 2024 · 0 comments

Comments

@Fragonite
Copy link

A client wanted a breakdown of where files are being stored and more details on the "other" mimetype. The below queries were used to help answer these questions.

I think this type of information is worth adding to the plugin.

Modules by data usage (all mimetypes):

SELECT 
    c.id AS course_id,
    c.fullname AS course_name,
    cm.id AS module_id,
    m.name AS module_name,
    CONCAT('<a href="/mod/', m.name, '/view.php?id=', cm.id, '">Module Link</a>') AS module_link,
    COUNT(f.id) AS file_count,
    ROUND(SUM(f.filesize) / 1024 / 1024 / 1024, 2) AS total_storage_gb
FROM 
    (SELECT DISTINCT ON (contenthash) * FROM {files}) f
JOIN 
    {context} ctx ON f.contextid = ctx.id
JOIN 
    {course_modules} cm ON ctx.instanceid = cm.id
JOIN 
    {modules} m ON cm.module = m.id
JOIN 
    {course} c ON cm.course = c.id
WHERE
    ctx.contextlevel = 70
GROUP BY 
    c.id, c.fullname, cm.id, m.name
ORDER BY 
    total_storage_gb DESC

Modules by data usage (video):

SELECT 
    c.id AS course_id,
    c.fullname AS course_name,
    cm.id AS module_id,
    m.name AS module_name,
    CONCAT('<a href="/mod/', m.name, '/view.php?id=', cm.id, '">Module Link</a>') AS module_link,
    COUNT(f.id) AS video_file_count,
    ROUND(SUM(f.filesize) / 1024 / 1024 / 1024, 2) AS total_storage_gb
FROM 
    (SELECT DISTINCT ON (contenthash) * FROM {files}) f
JOIN 
    {context} ctx ON f.contextid = ctx.id
JOIN 
    {course_modules} cm ON ctx.instanceid = cm.id
JOIN 
    {modules} m ON cm.module = m.id
JOIN 
    {course} c ON cm.course = c.id
WHERE 
    f.mimetype LIKE 'video/%'
    AND ctx.contextlevel = 70
GROUP BY 
    c.id, c.fullname, cm.id, m.name
ORDER BY 
    total_storage_gb DESC

Users by data usage (all mimetypes):

SELECT 
    u.id AS user_id,
    u.username,
    CONCAT('<a href="/user/profile.php?id=', u.id, '">Profile Link</a>') AS user_profile_link,
    COUNT(f.id) AS file_count,
    ROUND(SUM(f.filesize) / 1024 / 1024 / 1024, 2) AS total_storage_gb
FROM 
    (SELECT DISTINCT ON (contenthash) * FROM {files}) f
JOIN 
    {user} u ON f.userid = u.id
GROUP BY 
    u.id, u.username
ORDER BY 
    total_storage_gb DESC

Users by data usage (video):

SELECT 
    u.id AS user_id,
    u.username,
    CONCAT('<a href="/user/profile.php?id=', u.id, '">Profile Link</a>') AS user_profile_link,
    COUNT(f.id) AS video_file_count,
    ROUND(SUM(f.filesize) / 1024 / 1024 / 1024, 2) AS total_storage_gb
FROM 
    (SELECT DISTINCT ON (contenthash) * FROM {files} WHERE mimetype LIKE 'video/%') f
JOIN 
    {user} u ON f.userid = u.id
GROUP BY 
    u.id, u.username
ORDER BY 
    total_storage_gb DESC

Data usage by mimetypes:

SELECT 
    f.mimetype,
    COUNT(f.id) AS file_count,
    ROUND(SUM(f.filesize) / 1024 / 1024 / 1024, 2) AS total_storage_gb
FROM 
    (SELECT DISTINCT ON (contenthash) * FROM {files}) f
GROUP BY 
    f.mimetype
ORDER BY 
    total_storage_gb DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant