Browse Source

fix: coderabbit suggestions

pull/9323/head
DarkPhoenix2704 2 months ago
parent
commit
c498ee63cc
  1. 5
      packages/nc-gui/components/nc/Popover.vue
  2. 9
      packages/nc-gui/composables/useProductFeed.ts
  3. 14
      packages/nocodb/src/services/utils.service.ts

5
packages/nc-gui/components/nc/Popover.vue

@ -38,7 +38,8 @@ const emit = defineEmits(['update:modelValue'])
const triggerRef = ref(null) const triggerRef = ref(null)
const popoverRef = ref(null) const popoverRef = ref(null)
const isOpen = ref(props.modelValue)
const isOpen = useVModel(props, 'modelValue', emit)
const popoverStyle = computed(() => ({ const popoverStyle = computed(() => ({
position: 'fixed', position: 'fixed',
@ -117,7 +118,6 @@ const updatePopoverPosition = () => {
const openPopover = () => { const openPopover = () => {
isOpen.value = true isOpen.value = true
emit('update:modelValue', true)
nextTick(() => { nextTick(() => {
updatePopoverPosition() updatePopoverPosition()
variant.value = 'enter' variant.value = 'enter'
@ -128,7 +128,6 @@ const closePopover = () => {
variant.value = 'leave' variant.value = 'leave'
setTimeout(() => { setTimeout(() => {
isOpen.value = false isOpen.value = false
emit('update:modelValue', false)
}, 300) }, 300)
} }

9
packages/nc-gui/composables/useProductFeed.ts

@ -82,8 +82,11 @@ export const useProductFeed = createSharedComposable(() => {
try { try {
const newFeeds = await $api.utils.feed({ last_published_at: lastPublishedAt }) const newFeeds = await $api.utils.feed({ last_published_at: lastPublishedAt })
if (typeof newFeeds === 'number') {
newFeedCount.value = newFeeds as unknown as number newFeedCount.value = newFeeds
} else if (typeof newFeeds === 'string') {
newFeedCount.value = 100
}
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} }
@ -103,7 +106,7 @@ export const useProductFeed = createSharedComposable(() => {
}) })
onUnmounted(() => { onUnmounted(() => {
if (intervalId) clearTimeout(intervalId.value) if (intervalId.value) clearTimeout(intervalId.value)
}) })
return { return {

14
packages/nocodb/src/services/utils.service.ts

@ -491,7 +491,10 @@ export class UtilsService {
per_page: string; per_page: string;
}; };
const cacheKey = `${CacheScope.PRODUCT_FEED}:${type}:${page}:${per_page}`; const perPage = Math.min(Math.max(parseInt(per_page, 10) || 10, 1), 100);
const pageNum = Math.max(parseInt(page, 10) || 1, 1);
const cacheKey = `${CacheScope.PRODUCT_FEED}:${type}:${pageNum}:${perPage}`;
const cachedData = await NocoCache.get(cacheKey, 'json'); const cachedData = await NocoCache.get(cacheKey, 'json');
@ -500,13 +503,14 @@ export class UtilsService {
return JSON.parse(cachedData); return JSON.parse(cachedData);
} catch (e) { } catch (e) {
this.logger.error(e?.message, e); this.logger.error(e?.message, e);
await NocoCache.del(cacheKey);
} }
} }
let payload = null; let payload = null;
if (dayjs().isAfter(this.lastSyncTime.add(3, 'hours'))) { if (dayjs().isAfter(this.lastSyncTime.add(3, 'hours'))) {
this.lastSyncTime = dayjs();
payload = await T.payload(); payload = await T.payload();
this.lastSyncTime = dayjs();
} }
let response; let response;
@ -517,8 +521,8 @@ export class UtilsService {
payload, payload,
{ {
params: { params: {
per_page, per_page: perPage,
page, page: pageNum,
type, type,
}, },
}, },
@ -533,7 +537,7 @@ export class UtilsService {
await NocoCache.setExpiring( await NocoCache.setExpiring(
cacheKey, cacheKey,
JSON.stringify(response.data, getCircularReplacer), JSON.stringify(response.data, getCircularReplacer),
isNaN(parseInt(process.env.NC_ATTACHMENT_EXPIRE_SECONDS)) Number.isNaN(parseInt(process.env.NC_ATTACHMENT_EXPIRE_SECONDS))
? 2 * 60 * 60 ? 2 * 60 * 60
: parseInt(process.env.NC_ATTACHMENT_EXPIRE_SECONDS), : parseInt(process.env.NC_ATTACHMENT_EXPIRE_SECONDS),
); );

Loading…
Cancel
Save