Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: reuse mw.config.get() query #248

Merged
merged 3 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/method/initQueryData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMwApi } from '../utils/mw'
import { mwConfig, useMwApi } from '../utils/mw'

export async function initQueryData() {
// Init
Expand All @@ -10,7 +10,7 @@ export async function initQueryData() {
query: { users, userinfo, specialpagealiases },
} = await useMwApi().get({
action: 'query',
ususers: mw.config.get('wgUserName'),
ususers: mwConfig.wgUserName,
meta: ['userinfo', 'siteinfo'],
list: ['users'],
uiprop: ['rights'],
Expand Down
5 changes: 2 additions & 3 deletions src/method/syncI18nData.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { resolvePath } from './_dir'

const config = mw.config.get()
import { mwConfig } from '../utils/mw'

// 设置
const cacheTime = 2 * 60 * 60 * 1000
Expand All @@ -20,7 +19,7 @@ const localCacheTime = 'i18n-cache-' + funcName + '-timestamp'
export async function syncI18nData(noCache) {
const now = new Date().getTime()
// 如果语言为 qqx,不返回任何东西
if (config.wgUserLanguage === 'qqx') {
if (mwConfig.wgUserLanguage === 'qqx') {
console.warn('[InPageEdit] User language is qqx')
return true
}
Expand Down
4 changes: 3 additions & 1 deletion src/module/_msg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { mwConfig } from '../utils/mw'

const funcName = 'InPageEdit'
const userLang = mw.config.get('wgUserLanguage')
const userLang = mwConfig.wgUserLanguage
const fallbacks = {
ab: 'ru',
ace: 'id',
Expand Down
11 changes: 5 additions & 6 deletions src/module/articleLink.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { _msg } from './_msg'
import { preference } from './preference'
import { quickEdit } from './quickEdit'

const config = mw.config.get()
import { mwConfig } from '../utils/mw'

/**
* @module articleLink 获取段落编辑以及编辑链接
Expand All @@ -27,10 +26,10 @@ export function articleLink(elements) {

// 缓存wiki相关变量
const href = anchor.href,
articlePath = config.wgArticlePath.replace('$1', ''),
wikiBaseURL = `${location.protocol}//${config.wgServer.split('//')[1]}`,
articlePath = mwConfig.wgArticlePath.replace('$1', ''),
wikiBaseURL = `${location.protocol}//${mwConfig.wgServer.split('//')[1]}`,
wikiArticleBaseURL = `${wikiBaseURL}${articlePath}`,
wikiScriptBaseURL = `${wikiBaseURL}${config.wgScriptPath}`
wikiScriptBaseURL = `${wikiBaseURL}${mwConfig.wgScriptPath}`

// 链接指向的既不是本wiki的 canonicalurl 也不是 permalink
if (
Expand Down Expand Up @@ -82,7 +81,7 @@ export function articleLink(elements) {
} else if (section !== null) {
options.section = section
}
if (!config.wgIsArticle) {
if (!mwConfig.wgIsArticle) {
options.reload = false
}
quickEdit(options)
Expand Down
4 changes: 2 additions & 2 deletions src/module/preference.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
import version from './version'
import { pluginStore } from './pluginStore'
import { _analytics, getSiteID } from './_analytics'
import { mwConfig } from '../utils/mw'

const InPageEdit = window.InPageEdit || {}
const config = mw.config.get()

/**
* @module preference 个人设置模块
Expand Down Expand Up @@ -517,7 +517,7 @@ export const preference = {
}

// 获取Analysis数据
const userName = config.wgUserName
const userName = mwConfig.wgUserName
$.get(`${analyticsApi}/query/user`, {
userName,
siteUrl: getSiteID(),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/hasRight.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @return {boolean}
*/
export const hasRight = function (right) {
const conf = window.mw.config.get()
const conf = mw.config.get() // Get the latest configuration (may have been called `mw.config.set()` before)
console.info(
'[InPageEdit] _hasRight',
right,
Expand Down