The following warnings occurred:
Warning [2] Undefined array key "pointsview" - Line: 1442 - File: inc/plugins/newpoints/core/hooks.php PHP 8.2.11 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/plugins/newpoints/core/hooks.php 1442 errorHandler->error_callback
/inc/class_plugins.php 142 newpoints_blockview
/showthread.php 471 pluginSystem->run_hooks



This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Tutorial Reduce attachments.php file resources usage.
Files
#1
Hi.

I use the attachment system quite often as an media system in forums. Take this site for example, I mainly use the system to manage images. I think it is unnecessary to load the whole `global.php` to serve its purpose, thus I decided to strip it out and only load what I find to be required for the script to properly work.

You can take a look to the attached images, basically the main visual difference should be the error system, which won't render the whole page, but users will be able to use the login form regardless.

This will save you from 2 queries (error load) up to 5 queries (successful load) by file load. If you take into account the number of loaded attachments by page load as `n`, you will save from `n*2` to `n*5` queries by page load. So, for example, if you are rendering 10 attached images in a page, you could save from 20 to 50 queries per page load.

This is enough for me to apply the changes.

Open `attachment.php`, and find:
PHP Code:
require_once "./global.php"

Replace with:
PHP Code:
$working_dir dirname(__FILE__);
if(!
$working_dir)
{
    
$working_dir '.';
}

$shutdown_queries $shutdown_functions = array();

require_once 
$working_dir.'/inc/init.php';

$groupscache $cache->read('usergroups');

if(!
is_array($groupscache))
{
    
$cache->update_usergroups();
    
$groupscache $cache->read('usergroups');
}

$current_page my_strtolower(basename(THIS_SCRIPT));

if(isset(
$mybb->input['thumbnail']))
{
    
define('NO_ONLINE'1);
}

require_once 
MYBB_ROOT.'inc/class_session.php';
$session = new session;
$session->init();
$mybb->session = &$session;

$mybb->user['ismoderator'] = is_moderator(0''$mybb->user['uid']);

$mybb->post_code generate_post_check();

if(isset(
$mybb->input['language']) && $lang->language_exists($mybb->get_input('language')) && verify_post_check($mybb->get_input('my_post_key'), true))
{
    
$mybb->settings['bblanguage'] = $mybb->get_input('language');
    
// If user is logged in, update their language selection with the new one
    
if($mybb->user['uid'])
    {
        if(isset(
$mybb->cookies['mybblang']))
        {
            
my_unsetcookie('mybblang');
        }

        
$db->update_query('users', array('language' => $db->escape_string($mybb->settings['bblanguage'])), "uid = '{$mybb->user['uid']}'");
    }
    
// Guest = cookie
    
else
    {
        
my_setcookie('mybblang'$mybb->settings['bblanguage']);
    }
    
$mybb->user['language'] = $mybb->settings['bblanguage'];
}
else if(!
$mybb->user['uid'] && !empty($mybb->cookies['mybblang']) && $lang->language_exists($mybb->cookies['mybblang']))
{
    
$mybb->settings['bblanguage'] = $mybb->cookies['mybblang'];
}
else if(!isset(
$mybb->settings['bblanguage']))
{
    
$mybb->settings['bblanguage'] = 'english';
}

$lang->set_language($mybb->settings['bblanguage']);

$lang->load('global');
$lang->load('messages');

if(
$mybb->cookies['lockoutexpiry'] && $mybb->cookies['lockoutexpiry'] < TIME_NOW)
{
    
my_unsetcookie('lockoutexpiry');


Update: As of 1.8.23 the login form isn't displayed within the no permission page or container.


Attached Files Thumbnail(s)
       
Reply