Skip to content

Commit

Permalink
Merge branch 'master' into perf_build
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt authored Jan 9, 2025
2 parents c37d418 + 27dae3e commit b56c5f0
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 48 deletions.
2 changes: 1 addition & 1 deletion dashboard/src/components/charts/LineChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const initOptions = {
const options = ref({
grid: {
top: 20,
left: 40,
left: 50,
right: 20,
bottom: data.value.datasets.length > 1 ? 60 : 30 // if there's legend show more space for it
},
Expand Down
16 changes: 15 additions & 1 deletion dashboard/src2/components/SiteOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@
</Button>
</AlertBanner>
<DismissableBanner
v-if="
v-if="$site.doc.eol_versions.includes($site.doc.version)"
class="col-span-1 lg:col-span-2"
title="Your site is on an End of Life version. Upgrade to the latest version to get the latest features and security updates."
:id="`${$site.name}-eol`"
>
<Button
class="ml-auto"
variant="outline"
link="https://frappecloud.com/docs/sites/version-upgrade"
>
Upgrade Now
</Button>
</DismissableBanner>
<DismissableBanner
v-else-if="
$site.doc.current_plan &&
!$site.doc.current_plan?.private_benches &&
$site.doc.group_public &&
Expand Down
47 changes: 33 additions & 14 deletions dashboard/src2/components/devtools/database/SQLCodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,38 @@ export default {
set(value) {
this.$emit('update:query', value);
}
},
extensions() {
if (!this.schema) {
return [
sql({
dialect: MySQL,
upperCaseKeywords: true
}),
autocompletion({
activateOnTyping: true,
closeOnBlur: false,
maxRenderedOptions: 10,
icons: false
})
];
}
return [
sql({
dialect: MySQL,
upperCaseKeywords: true,
schema: this.schema
}),
autocompletion({
activateOnTyping: true,
closeOnBlur: false,
maxRenderedOptions: 10,
icons: false
})
];
}
},
setup(props, { emit }) {
const extensions = [
sql({
dialect: MySQL,
upperCaseKeywords: true,
schema: props.schema
}),
autocompletion({
activateOnTyping: true,
closeOnBlur: false,
maxRenderedOptions: 10,
icons: false
})
];
// Codemirror EditorView instance ref
const view = shallowRef();
const handleReady = payload => {
Expand All @@ -66,13 +82,16 @@ export default {
selection.from,
selection.to
);
if ((selectedText ?? '').trim() === '') {
emit('codeUnselected');
return;
}
emit('codeSelected', selectedText);
} else {
emit('codeUnselected');
}
};
return {
extensions,
handleReady
};
}
Expand Down
11 changes: 9 additions & 2 deletions dashboard/src2/components/server/ServerCharts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
:data="cpuData"
unit="%"
:chartTheme="[
$theme.colors.green[500], // idle
$theme.colors.red[500], // iowait
$theme.colors.yellow[500], // irq
$theme.colors.pink[500], // nice
$theme.colors.purple[500], // softirq
$theme.colors.blue[500], // steal
$theme.colors.teal[500], // system
$theme.colors.cyan[500] // user
$theme.colors.cyan[500], // user
$theme.colors.green[500] // idle
]"
:loading="$resources.cpu.loading"
:error="$resources.cpu.error"
Expand Down Expand Up @@ -708,6 +708,13 @@ export default {
let cpu = this.$resources.cpu.data;
if (!cpu) return;
// move idle to the end
cpu.datasets = cpu.datasets.sort((a, b) => {
if (a.name === 'idle') return 1;
if (b.name === 'idle') return -1;
return 0;
});
return this.transformMultiLineChartData(cpu, 'cpu', true);
},
memoryData() {
Expand Down
18 changes: 15 additions & 3 deletions dashboard/src2/pages/NewSite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,19 @@
"
>
<span class="font-medium">{{ v.name }} </span>
<span class="ml-1 text-gray-600">
{{ v.status }}
</span>
<div
v-if="v.status === 'Develop'"
class="flex items-center gap-2"
>
<Tooltip
text="This version is under development and may have bugs. Do not use for production sites."
>
<i-lucide-info class="h-4 w-4 text-gray-500" />
</Tooltip>
<span class="ml-1 text-gray-600">
{{ v.status }}
</span>
</div>
</button>
</component>
</div>
Expand Down Expand Up @@ -266,6 +276,7 @@ import NewSiteAppSelector from '../components/site/NewSiteAppSelector.vue';
import Summary from '../components/Summary.vue';
import { DashboardError } from '../utils/error';
import { getCountry } from '../utils/country';
import AlertBanner from '../components/AlertBanner.vue';
export default {
name: 'NewSite',
Expand All @@ -276,6 +287,7 @@ export default {
SitePlansCards,
Autocomplete,
ErrorMessage,
AlertBanner,
FormControl,
FeatherIcon,
TextInput,
Expand Down
17 changes: 16 additions & 1 deletion dashboard/src2/pages/ReleaseGroupBenchSites.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<template>
<div>
<DismissableBanner
v-if="$releaseGroup.doc.eol_versions.includes($releaseGroup.doc.version)"
class="col-span-1 lg:col-span-2"
title="Your sites are on an End of Life version. Upgrade to the latest version to get the latest features and security updates."
:id="`${$releaseGroup.name}-eol`"
>
<Button
class="ml-auto"
variant="outline"
link="https://frappecloud.com/docs/sites/version-upgrade"
>
Upgrade Now
</Button>
</DismissableBanner>
<ObjectList class="mt-3" :options="listOptions" />
<Dialog
v-model="showAppVersionDialog"
Expand Down Expand Up @@ -33,11 +47,12 @@ import {
} from '../objects/common';
import { confirmDialog, icon, renderDialog } from '../utils/components';
import { getToastErrorMessage } from '../utils/toast';
import DismissableBanner from '../components/DismissableBanner.vue';
export default {
name: 'ReleaseGroupBenchSites',
props: ['releaseGroup'],
components: { ObjectList },
components: { ObjectList, DismissableBanner },
data() {
return {
showAppVersionDialog: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@

<!-- Queries Information -->
<ToggleContent
class="mt-5"
class="mt-3"
label="SQL Query Analysis"
subLabel="Check the concerning queries that might be affecting your database performance"
>
Expand Down
37 changes: 19 additions & 18 deletions dashboard/src2/pages/devtools/database/DatabaseSQLPlayground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
v-model="site"
/>
<Button
iconLeft="refresh-ccw"
icon="refresh-ccw"
variant="subtle"
:loading="site && !isSQLEditorReady"
:loading="site && !isAutoCompletionReady"
:disabled="!site"
@click="
() =>
Expand All @@ -57,19 +57,27 @@
</Header>
<div class="m-5">
<!-- body -->
<div class="mt-2 flex flex-col" v-if="isSQLEditorReady">
<div
v-if="!site"
class="flex h-full min-h-[80vh] w-full items-center justify-center gap-2 text-gray-700"
>
Select a site to get started
</div>
<div class="mt-2 flex flex-col" v-else>
<div class="overflow-hidden rounded border">
<SQLCodeEditor
v-model="query"
v-if="sqlSchemaForAutocompletion"
:schema="sqlSchemaForAutocompletion"
@codeSelected="handleCodeSelected"
@codeUnselected="handleCodeUnselected"
/>
</div>
<div class="mt-2 flex flex-row items-center justify-between">
<div class="flex gap-2">
<Button iconLeft="table" @click="toggleTableSchemasDialog"
<Button
iconLeft="table"
@click="toggleTableSchemasDialog"
:disabled="!isAutoCompletionReady"
>Tables</Button
>
<Button iconLeft="file-text" @click="toggleLogsDialog">Logs</Button>
Expand Down Expand Up @@ -120,18 +128,7 @@
</div>
</div>
</div>
<div
v-else-if="!site"
class="flex h-full min-h-[80vh] w-full items-center justify-center gap-2 text-gray-700"
>
Select a site to get started
</div>
<div
class="flex h-full min-h-[80vh] w-full items-center justify-center gap-2 text-gray-700"
v-else
>
<Spinner class="w-4" /> Setting Up SQL Playground
</div>

<DatabaseSQLPlaygroundLog
v-if="this.site"
:site="this.site"
Expand Down Expand Up @@ -277,7 +274,7 @@ export default {
children: childrenSchemas
};
},
isSQLEditorReady() {
isAutoCompletionReady() {
if (this.$resources.tableSchemas.loading) return false;
if (this.$resources.tableSchemas?.data?.message?.loading) return false;
if (!this.$resources.tableSchemas?.data?.message?.data) return false;
Expand Down Expand Up @@ -373,6 +370,10 @@ Are you sure you want to run the query?
this.showLogsDialog = !this.showLogsDialog;
},
toggleTableSchemasDialog() {
if (!this.isAutoCompletionReady) {
toast.error('Table schemas are still loading. Please wait.');
return;
}
this.showTableSchemasDialog = !this.showTableSchemasDialog;
},
rerunQuery(query) {
Expand Down
2 changes: 1 addition & 1 deletion press/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
"0 8 * * *": [
"press.press.doctype.aws_savings_plan_recommendation.aws_savings_plan_recommendation.create",
],
"0 18 * * *": [
"0 21 * * *": [
"press.press.audit.billing_audit",
"press.press.audit.partner_billing_audit",
],
Expand Down
24 changes: 24 additions & 0 deletions press/press/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def __init__(self):
"Sites active after trial": self.free_sites_after_trial,
"Teams with active sites and unpaid Invoices": self.teams_with_active_sites_and_unpaid_invoices,
"Prepaid Unpaid Invoices with Stripe Invoice ID set": self.prepaid_unpaid_invoices_with_stripe_invoice_id_set,
"Subscriptions with duplicate usage records created": self.subscriptions_with_duplicate_usage_records,
}

log = {a: [] for a in audits}
Expand Down Expand Up @@ -366,6 +367,29 @@ def subscriptions_without_usage_record(self):
pluck="name",
)

def subscriptions_with_duplicate_usage_records(self):
data = frappe.db.sql(
"""
SELECT subscription, Count(name) as count
FROM `tabUsage Record` as UR
WHERE UR.date = CURDATE()
AND UR.docstatus = 1
AND UR.plan NOT LIKE '%Marketplace%'
GROUP BY UR.document_name, UR.plan, UR.team
HAVING count > 1
ORDER BY count DESC
""",
as_dict=True,
)

if not data:
return data

result = []
for d in data:
result.append(d.subscription)
return result

def disabled_teams_with_active_sites(self):
return frappe.get_all(
"Team",
Expand Down
7 changes: 7 additions & 0 deletions press/press/doctype/release_group/release_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ def get_doc(self, doc):
doc.status = self.status
doc.actions = self.get_actions()
doc.are_builds_suspended = are_builds_suspended()
doc.eol_versions = frappe.db.get_all(
"Frappe Version",
filters={"status": "End of Life"},
fields=["name"],
order_by="name desc",
pluck="name",
)

if len(self.servers) == 1:
server = frappe.db.get_value("Server", self.servers[0].server, ["team", "title"], as_dict=True)
Expand Down
7 changes: 7 additions & 0 deletions press/press/doctype/site/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ def get_doc(self, doc):
doc.latest_frappe_version = frappe.db.get_value(
"Frappe Version", {"status": "Stable", "public": True}, order_by="name desc"
)
doc.eol_versions = frappe.db.get_all(
"Frappe Version",
filters={"status": "End of Life"},
fields=["name"],
order_by="name desc",
pluck="name",
)
doc.owner_email = frappe.db.get_value("Team", self.team, "user")
doc.current_usage = self.current_usage
doc.current_plan = get("Site Plan", self.plan) if self.plan else None
Expand Down
4 changes: 2 additions & 2 deletions press/press/doctype/subscription/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import rq
from frappe.model.document import Document
from frappe.query_builder.functions import Coalesce, Count
from frappe.utils import cint
from frappe.utils import cint, flt

from press.overrides import get_permission_query_conditions_for_doctype
from press.press.doctype.site_plan.site_plan import SitePlan
Expand Down Expand Up @@ -152,7 +152,7 @@ def create_usage_record(self, date: DF.Date | None = None):
if self.additional_storage:
price = plan.price_inr if team.currency == "INR" else plan.price_usd
price_per_day = price / plan.period # no rounding off to avoid discrepancies
amount = price_per_day * cint(self.additional_storage)
amount = flt((price_per_day * cint(self.additional_storage)), 2)
else:
amount = plan.get_price_for_interval(self.interval, team.currency)

Expand Down
1 change: 0 additions & 1 deletion press/press/doctype/usage_record/usage_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def validate_duplicate_usage_record(self):
"plan": self.plan,
"docstatus": 1,
"subscription": self.subscription,
"invoice": self.invoice,
},
pluck="name",
)
Expand Down
Loading

0 comments on commit b56c5f0

Please sign in to comment.