# Optimization

## Client Side

{% hint style="info" %}

### IDLE

{% endhint %}

<figure><img src="https://2054689962-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2jFzR30XlKSdobBggZNg%2Fuploads%2F4R1OVZVyojEWs84OuVv6%2Fresmon_1.png?alt=media&#x26;token=5a571d7e-3afe-496a-aebd-1b9598e3cb94" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

### When Nearby A Room

{% endhint %}

<figure><img src="https://2054689962-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2jFzR30XlKSdobBggZNg%2Fuploads%2Fe7ojVXUdW6ZFegUyFKNK%2Fresmon_2.png?alt=media&#x26;token=ef09d662-5d9c-481e-9526-5d54f1048489" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}

### When Nearby The Text And Marker

{% endhint %}

<figure><img src="https://2054689962-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2jFzR30XlKSdobBggZNg%2Fuploads%2Fcv8B8soVrO6w1kZco7eL%2Fresmon_3.png?alt=media&#x26;token=9bba2372-19ec-4803-89af-dd0edb354fc4" alt=""><figcaption></figcaption></figure>

## Server Side

{% hint style="info" %}

### All Sql Queries Are Perfectly Optimized

{% endhint %}

### Example Code

```lua
function SaveCustomers()
    if next(PlayersMotels) then
        local selectList = ''
        local formatQuery = ([[
            SELECT '%s' AS owner, %s AS py, '%s' AS mtl, %s AS rmid, '%s' AS unq, '%s' AS reqs, %s as susp, '%s' as sh, %s as st, %s as ed, '%s' as wn
        ]])
        local total = 0
        for k,v in pairs(PlayersMotels) do
            total+= 1
            if selectList == '' then 
                selectList = ([[
                    UPDATE mx_motels u JOIN (%s
                ]]):format(formatQuery:format(k, v.pay, v.motel, v.roomId, v.uniq, json.encode(v.requests), v.suspended, json.encode(v.shared), v.startTime, v.endTime, json.encode(v.warn)))
                goto continue
            end
            selectList = selectList .. ([[
                UNION %s
            ]]):format(formatQuery:format(k, v.pay, v.motel, v.roomId, v.uniq, json.encode(v.requests), v.suspended, json.encode(v.shared), v.startTime, v.endTime, json.encode(v.warn)))
            ::continue::
        end
        if selectList == '' then return end
        selectList = selectList .. [[
            ) AS t ON u.owner = t.owner
           SET pay = py,
            motel = mtl, 
            `roomId` = rmid,
            uniq = unq,
            requests = reqs,
            suspended = susp,
            `shared` = sh,
            `startTime` = st,
            `endTime` = ed,
            `warn` = wn
        ]]
        ExecuteSQL(selectList)
        Debug('Saved ^2'..total..'^1 Customers(s) ^0')
    end
end
```
