Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 877499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:37:11+00:00 2026-05-15T11:37:11+00:00

For the current app I am writing I have elected to place all database

  • 0

For the current app I am writing I have elected to place all database functionality into a single class, as it allows me to keep the database code away from the business logic and easily replace the database code if we ever have need to switch to another DBMS. However, recently my database class has become rather large (EDIT for info: approximately 53k), and I’m worried about the speed of parsing this file due to its volume, since it generally must be parsed for each request.

Typically only one, or maybe two, different “Types” of database calls are made (e.g., user system calls, asset system calls, map system calls, session system calls, etc) at any given time, so one option I was considering was breaking the tasks into a series of database object “slices” and then dynamically loading those at run time based on the functions requests.

On the other hand, I’m worried that doing this would either (a) lead to a large amount of parallel execution in memory (i.e., each slice now has a query method, an independent query log, etc) as well as forcing me to modify all the existing code to point to the new, smaller objects or (b) cause relative performance losses as I back-hack in this functionality to work with the code that’s already written (e.g., have each slice point back to the parent’s querying functions as well as the performance hit to be incurred by suddenly using __call all over the place instead of direct method access).

What is the more correct course of action in this scenario?

EDIT For More Info: The file is approximately 53kb with about 2,350 lines at present (and it is not done), although this may be considered skewed as I use an expanded SQL model for readability, e.g.

SELECT
    foo,
    bar,
    baz
FROM
    someTable st
    LEFT JOIN someOtherTable sot
        ON st.id = sot.stId
WHERE
    cond > otherCond

There are 70 querying functions, each one performing some unique task, with very little overlap (If I need two startlingly similar result sets I can simply ignore what I don’t need each time and reuse the same queries).

EDIT: Example function:

public function alarm_getActiveAlarmsByAsset($tier, $id) {
    if (    !Redacted::checkNumber($tier, $id) 
        ||  $id < 0 
        ||  $tier > Redacted::ASSET_LOWEST_TIER 
        ||  $tier < Redacted::ASSET_TIER_CUSTOMER
    ) {
        return false;
    }

    $sql = "
        SELECT
            alarmId,
            alarmTime,
            server,
            source,
            reason,
            train,
            server_sites.siteId AS `siteId`
        FROM
            alarm_alarms
    ";

    $join = '';

    switch ($tier) {
        case Redacted::ASSET_TIER_CUSTOMER:
            $join = '
                LEFT JOIN red_campus
                    ON red_campus.campId = red_site.campId
            ';
        case Redacted::ASSET_TIER_CAMPUS:
            $join = '
                LEFT JOIN red_site
                    ON red_site.siteId = server_sites.siteId
            ' . $join;
        case Redacted::ASSET_TIER_SITE:
            $join = '
                LEFT JOIN server_sites
                    ON server_sites.servId = alarm_alarms.server
            ' . $join;
    }
    $table = isset(self::$dbTierMap[$tier + 1]) ? self::$dbTierMap[$tier + 1]['table'] : 'server_sites';
    $field = isset(self::$dbTierMap[$tier + 1]) ? self::$dbTierMap[$tier + 1]['parent'] : 'site';
    $sql .= $join . "
        WHERE
                ackId IS NULL
            AND {$table}.{$field}Id = {$id}
    ";

    $r = $this->query($sql);

    if (!$r) {
        return false;
    }

    $alarms = array();
    while ($alarm = mysql_fetch_assoc($r)) {
        $alarms[] = $alarm;
    }
    return $alarms;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:37:11+00:00Added an answer on May 15, 2026 at 11:37 am

    If you are worried about parsing time, and not code quality, you could use some compiler cache, such as APC.

    However, if you have a big class, it’s likely that you should refactor it into smaller ones just for readability. If you can’t easily find what you need in the class (to modify it, for example), then it’s probably too big to maintain.
    If you decide to refactor, remember that maintainability and code quality are far more important than execution speed (database I/O is slower than executing code anyway).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that display's the current time when a page opens. I
I have a requirement on my current project (a Flex app which will be
I have Windows Vista MCML app, and I need to figure out the current
I am writing an app that requires the user's current location (lastknownlocation won't be
I have Winform app I am writing in C#. On my form, I have
I'll be tackling writing a custom date validation class tomorrow for a meeting app
I'm writing an android app that takes your current location and returns a list
My current app needs to store address information for a user. I'm currently debating
I need to integrate a email client in my current python web app. Anything
How do you get the current directory where your app is running?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.