flarum / issue-archive

0 stars 0 forks source link

Live update the post scrubber date #50

Open davwheat opened 3 years ago

davwheat commented 3 years ago

Feature Request

Is your feature request related to a problem? Please describe. Currently, the post scrubber post number updates as you drag it, but the date below doesn't. We should make the date update as we move the scrubber, too.

Justify why this feature belongs in Flarum's core, rather than in a third-party extension The post scrubber is a core feature, but its functionality could be seen as confusing due to some content updating but others not.

Describe alternatives you've considered None

Solution I think the best way to achieve this would be passing a start and end index for every month as part of the discussion data.

{
  // discussion data
  timePeriods: [
    { year: 2020, month: 7, startIndex: 0, endIndex: 12 },
    { year: 2021, month: 8, startIndex: 13, endIndex: 17 },
  ]
}

We can then process this on the frontend:

interface ITimePeriod {
  year: number;
  month: number;
  startIndex: number;
  endIndex: number;
}

// ...

const timePeriods: ITimePeriod[] = discussion.timePeriods();
const currentIndex = 14;

const currentPeriod = timePeriods.find((period) => {
  return currentIndex >= period.startIndex && currentIndex <= period.endIndex;
})

console.log(currentPeriod);
// { year: 2021, month: 8, startIndex: 13, endIndex: 17 }
luceos commented 3 years ago

If I'm not mistaken another issue speaks about the detrimental performance due to loading all posts numbers so that the scrubber can be rendered. A proposal that removes that performance issue while introducing the above would be a huge win imo.

askvortsov1 commented 3 years ago

If I'm not mistaken another issue speaks about the detrimental performance due to loading all posts numbers so that the scrubber can be rendered. A proposal that removes that performance issue while introducing the above would be a huge win imo.

Instead of querying the IDs of all posts in the discussion, we should add creation time to the pivot table. We'll also need to support a way to "fetch multiple columns in a single query. If we used our current serializer approach, we'd end up serially doing one query for every post in the discussion. If we could get all IDs and timestamps in one query, then we'd have a chance at implementing this.