Skip to content

Commit

Permalink
Syncing files from cloud/release/2024.001 to release/2024.001
Browse files Browse the repository at this point in the history
  • Loading branch information
Crousem committed Feb 5, 2024
1 parent 72fd382 commit 6b433d1
Show file tree
Hide file tree
Showing 36 changed files with 437 additions and 184 deletions.
2 changes: 1 addition & 1 deletion applications/dashboard/models/DeveloperProfileModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(ConfigurationInterface $config)
$this->config = $config;
parent::__construct(self::TABLE_NAME);
$this->addPipelineProcessor(
new PruneProcessor("dateRecorded", "7 days", 100, [
new PruneProcessor("dateRecorded", "1 days", 100, [
"isTracked" => false,
])
);
Expand Down
15 changes: 6 additions & 9 deletions applications/dashboard/models/QueuedJobModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ public function __construct(
) {
parent::__construct(self::TABLE_NAME);
$this->addPipelineProcessor(new JsonFieldProcessor(["message", "metrics"]));
$successPruneDuration = $config->get("JobQueue.SuccessPruneDuration", "3 days");
$this->addPipelineProcessor(
new PruneProcessor("dateUpdated", "3 days", 100, [
"status" => [self::STATUS_SUCCESS],
])
);
$this->addPipelineProcessor(new PruneProcessor("dateUpdated", "1 month", 100));
$this->addPipelineProcessor(new PruneProcessor("dateUpdated", "2 weeks", 100));
$this->lockService = $lockService;
$this->config = $config;
$this->scheduler = $scheduler;
Expand Down Expand Up @@ -241,12 +242,11 @@ public function insert(array $set, array $options = [])
}

/**
* Check to schedule Job
* @param string $jobDescriptor Class name of the job to schedule
* Check if we should flush any pending jobs.
*
* @throws \Exception
* @return bool
*/
public function checkToScheduleJob(string $jobDescriptor)
public function shouldFlushPendingJobs(): bool
{
$subquery = $this->createSql();
$subquery
Expand Down Expand Up @@ -275,10 +275,7 @@ public function checkToScheduleJob(string $jobDescriptor)
}

// Trigger job when we have jobThreshold(default 50) number of jobs queued, or latest queued job was queued 1 minute ago.
if ($pendingCount >= $this->getJobThreshold() || $hasEarlyJob) {
$jobDescriptor = new NormalJobDescriptor($jobDescriptor);
$this->scheduler->addJobDescriptor($jobDescriptor);
}
return $pendingCount >= $this->getJobThreshold() || $hasEarlyJob;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion applications/dashboard/models/class.usermodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5823,7 +5823,10 @@ public function getAttribute($userID, $attribute, $defaultValue = false)
{
$user = $this->getID($userID, DATASET_TYPE_ARRAY);
$result = val($attribute, $user["Attributes"], $defaultValue);

// return same default value type
if (is_array($defaultValue) && $result === false) {
$result = $defaultValue;
}
return $result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function clearDiscussionSelections($transientKey = "")
{
$session = Gdn::session();
if ($session->validateTransientKey($transientKey)) {
Gdn::userModel()->saveAttribute($session->UserID, "CheckedDiscussions", false);
Gdn::userModel()->saveAttribute($session->UserID, "CheckedDiscussions", []);
}

redirectTo(getIncomingValue("Target", "/discussions"));
Expand Down
8 changes: 8 additions & 0 deletions build/scripts/configs/makeBaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ export async function makeBaseConfig(entryModel: EntryModel, section: string) {
'link[rel="stylesheet"][static="1"]',
);
const lastStaticStylesheet = staticStylesheets[staticStylesheets.length - 1];

const firstStyleTag = document.head.querySelector("style");
if (lastStaticStylesheet) {
document.head.insertBefore(element, lastStaticStylesheet.nextSibling);
} else if (firstStyleTag) {
document.head.insertBefore(element, firstStyleTag);
} else {
document.head.appendChild(element);
}
Expand Down Expand Up @@ -192,6 +196,10 @@ export async function makeBaseConfig(entryModel: EntryModel, section: string) {
VANILLA_ROOT,
"library/src/scripts/leaderboardWidget/LeaderboardWidget.styles.ts",
),
"@library/embeddedContent/embedService": path.resolve(
VANILLA_ROOT,
"library/src/scripts/embeddedContent/embedService.register.tsx",
),
...entryModel.aliases,
"library-scss": path.resolve(VANILLA_ROOT, "library/src/scss"),
"react-select": require.resolve("react-select/dist/react-select.esm.js"),
Expand Down
10 changes: 5 additions & 5 deletions library/Garden/Web/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(
$this->locale = $locale;
$this->container = $container;
$this->eventManager = $eventManager ?? new EventManager();
$this->timers = $timers ?? new Timers();
// $this->timers = $timers ?? new Timers();
}

/**
Expand Down Expand Up @@ -136,13 +136,13 @@ public function getRoute($key)
*/
public function dispatch(RequestInterface $request)
{
$span = $this->timers->startRequest($request);
// $span = $this->timers->startRequest($request);
try {
$result = $this->callMiddleware($request);
} catch (\Throwable $ex) {
$result = $this->makeResponse($ex);
} finally {
$span->finish($result ? $result->asHttpResponse() : null);
// $span->finish($result ? $result->asHttpResponse() : null);
}
return $result;
}
Expand All @@ -162,9 +162,9 @@ protected function dispatchInternal(RequestInterface $request)

foreach ($this->routes as $route) {
try {
$routeMatchSpan = $this->timers->startGeneric("route-match");
// $routeMatchSpan = $this->timers->startGeneric("route-match");
$action = $route->match($request);
$routeMatchSpan->finish();
// $routeMatchSpan->finish();
if ($action instanceof \Exception) {
// Hold the action in case another route succeeds.
$ex = $action;
Expand Down
7 changes: 5 additions & 2 deletions library/Vanilla/Scheduler/DeferredScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,8 @@ protected function dispatchAll(): array
/** @var TrackingSlip $trackingSlip */
foreach ($this->generateTrackingSlips() as $trackingSlip) {
$trackingSlip->start();
$jobClass = $trackingSlip->getJobInterface();
$span = $this->timers->startGeneric("dispatchJob", [
"name" => "Job: $jobClass",
"name" => "Job: {$trackingSlip->getType()}",
"trackingID" => $trackingSlip->getTrackingID(),
]);
try {
Expand Down Expand Up @@ -387,6 +386,10 @@ protected function dispatchAll(): array
$trackingSlip->log();
}
}

foreach ($this->drivers as $driver) {
$driver->cleanupAfterDispatch();
}
return $this->trackingSlips;
}

Expand Down
7 changes: 7 additions & 0 deletions library/Vanilla/Scheduler/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ public function execute(DriverSlipInterface $driverSlip): JobExecutionStatus;
* @return array
*/
public function getSupportedInterfaces(): array;

/**
* Use this method to have your driver perform any necessary cleanup after all jobs have been executed.
*
* @return void
*/
public function cleanupAfterDispatch(): void;
}
8 changes: 8 additions & 0 deletions library/Vanilla/Scheduler/Driver/LocalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ public function getSupportedInterfaces(): array
{
return [LocalJobInterface::class];
}

/**
* @inheritdoc
*/
public function cleanupAfterDispatch(): void
{
// Nothing to do here.
}
}
8 changes: 8 additions & 0 deletions library/Vanilla/Utility/StringUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Vanilla\Utility;

use Firebase\JWT\JWT;
use function Sodium\add;

/**
* A collection of string utilities.
Expand Down Expand Up @@ -237,6 +238,13 @@ public static function flattenArray($rows, $prefix = "")
} elseif (is_array($value)) {
$result = $result + self::flattenArray($value, $prefix . $key . ".");
} else {
if (is_string($value)) {
// Remove escaped quotes since those are not processed by the CSV generator.
$value = str_replace("\\\"", "\"", $value);

// Escape next line to prevent text from breaking.
$value = str_replace("\n", "\\n", $value);
}
$result[$prefix . $key] = $value;
}
}
Expand Down
4 changes: 2 additions & 2 deletions library/Vanilla/Utility/Timers.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ private function shouldRecordProfile(): bool
$session = \Gdn::session();
$config = \Gdn::config();

if (!$config->get("trace.profiler", true)) {
// Never record traces if the feature is disabled. On by default.
if (!$config->get("trace.profiler", false)) {
// Never record traces if the feature is disabled. Off by default.
return false;
}

Expand Down
12 changes: 11 additions & 1 deletion library/Vanilla/Web/MasterViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public function renderGdnController(\Gdn_Controller $controller): string

$bodyHtmlKey = $controller->getIsReactView() ? "seoContent" : "bodyContent";

foreach ($this->getFontCssUrls() as $fontCssUrl) {
$modernPageHead = \Gdn::getContainer()->get(PageHead::class);
$inlineContent = $modernPageHead->getInlineStyleFromUrl($fontCssUrl);
if ($inlineContent !== null) {
$controller->Head->addString("<style>{$inlineContent}</style>");
} else {
$controller->Head->addCss($fontCssUrl);
}
}

$extraData = [
$bodyHtmlKey => $this->renderThemeContentView($data) ?? $controller->renderAssetForTwig("Content"),
"cssClasses" =>
Expand Down Expand Up @@ -191,7 +201,7 @@ private function getFontCssUrls(): array
$fontsAssetUrls = array_column($fontsAssets, "url");

$variables = $this->themePreloader->getVariables();
$fontVars = $variables["font"] ?? [];
$fontVars = $variables["global"]["fonts"] ?? [];

$customFontUrl = $fontVars["customFont"]["url"] ?? ($fontVars["customFontUrl"] ?? null);
$forceGoogleFont = $fontVars["forceGoogleFont"] ?? false;
Expand Down
2 changes: 1 addition & 1 deletion library/core/class.email.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public function send($eventName = "")
try {
$this->mailer->send();
} finally {
$span->stopTimer();
$span->finish();
}

if ($this->isDebug() && $this->logger instanceof Psr\Log\LoggerInterface) {
Expand Down
1 change: 1 addition & 0 deletions library/core/class.proxyrequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ public function request($options = null, $queryParams = null, $files = null, $ex
curl_setopt($handler, CURLOPT_CONNECTTIMEOUT, $connectTimeout);
curl_setopt($handler, CURLOPT_HEADERFUNCTION, [$this, "CurlHeader"]);
curl_setopt($handler, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_setopt($handler, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

if ($transferMode == "binary") {
curl_setopt($handler, CURLOPT_BINARYTRANSFER, true);
Expand Down
7 changes: 6 additions & 1 deletion library/core/class.session.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,12 @@ public function getPreference($preferenceName, $defaultValue = false)
public function getAttribute($attributeName, $defaultValue = false)
{
if (is_array($this->_Attributes)) {
return val($attributeName, $this->_Attributes, $defaultValue);
$value = val($attributeName, $this->_Attributes, $defaultValue);
// return same default value type
if (is_array($defaultValue) && $value === false) {
$value = $defaultValue;
}
return $value;
}
return $defaultValue;
}
Expand Down
12 changes: 10 additions & 2 deletions library/src/scripts/categoriesWidget/CategoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { HomeWidgetContainer } from "@library/homeWidget/HomeWidgetContainer";
import { WidgetContainerDisplayType } from "@library/homeWidget/HomeWidgetContainer.styles";
import { updateCategoryFollowCount } from "@library/categoriesWidget/CategoriesWidget.utils";
import cloneDeep from "lodash/cloneDeep";
import isEqual from "lodash/isEqual";

export function CategoryList(props: ICategoriesWidgetProps) {
const classes = categoryListClasses();
Expand All @@ -25,13 +26,20 @@ export function CategoryList(props: ICategoriesWidgetProps) {
contentType: props.itemOptions?.contentType,
};

const [categories, setCategories] = useState<ICategoryItem[]>(cloneDeep(props.itemData));
const itemData = cloneDeep(props.itemData);

const [categories, setCategories] = useState<ICategoryItem[]>(itemData);
const [categoryWithFollowCountChange, setCategoryWithFollowCountChange] = useState<{
categoryID: ICategoryItem["categoryID"];
preferences: ICategoryItem["preferences"];
} | null>(null);

useEffect(() => {
// reset the state if itemData from props is changed
if (!isEqual(categories, itemData)) {
setCategories(itemData);
}

if (categoryWithFollowCountChange) {
const updatedCategories = updateCategoryFollowCount(
categories,
Expand All @@ -44,7 +52,7 @@ export function CategoryList(props: ICategoriesWidgetProps) {
}
setCategoryWithFollowCountChange(null);
}
}, [categoryWithFollowCountChange]);
}, [categoryWithFollowCountChange, itemData]);

const onCategoryFollowChange = (categoryWithNewPreferences: {
categoryID: ICategoryItem["categoryID"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ export const discussionListClasses = useThemeCache(
},
});

const disablePointerEvents = css({
pointerEvents: "none",
});

return {
title,
iconAndVoteCounterWrapper,
Expand All @@ -223,6 +227,7 @@ export const discussionListClasses = useThemeCache(
filterAndSortingLabel,
filterAndSortingDropdown,
filterAndSortingButton,
disablePointerEvents,
};
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export function DiscussionListAsset(props: IProps) {
pinOrder: getPinOrder(sort),
};

// we always receive this from props, so reset it here to avoid categoryID from previous page/state if navigating between react pages
if (props.apiParams?.categoryID) {
finalParams.categoryID = props.apiParams?.categoryID;
}

// In case a community manager shared a link that had one of these set.
// Display a permission error and exclude the parameter.
if (finalParams.internalStatusID?.length && !isCommunityManager) {
Expand Down Expand Up @@ -125,6 +130,7 @@ export function DiscussionListAsset(props: IProps) {
paginationProps={paginationProps}
apiParams={actualApiParams}
updateApiParams={updateApiParams}
isPreview={props.isPreview}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ interface IProps {
paginationProps?: INumberedPagerProps;
apiParams: IGetDiscussionListParams;
updateApiParams: (newParams: Partial<IGetDiscussionListParams>) => void;
isPreview?: boolean;
}

/**
* Header component for discussion list asset.
*/
export function DiscussionListAssetHeader(props: IProps) {
const { updateApiParams, apiParams } = props;
const { updateApiParams, apiParams, isPreview } = props;
const classes = discussionListClasses();
const { hasPermission } = usePermissionsContext();
const canUseCheckboxes =
Expand All @@ -39,7 +40,7 @@ export function DiscussionListAssetHeader(props: IProps) {
const isMobile = measure.width < 600;

return (
<div className={cx(classes.assetHeader)} ref={selfRef}>
<div className={cx(classes.assetHeader, { [classes.disablePointerEvents]: isPreview })} ref={selfRef}>
<div>
{canUseCheckboxes && (
<DiscussionListSelectAll
Expand Down

0 comments on commit 6b433d1

Please sign in to comment.